Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created June 2, 2021 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibelius/1d7707f4a0c10b0dce2f105fb3a81dcd to your computer and use it in GitHub Desktop.
Save sibelius/1d7707f4a0c10b0dce2f105fb3a81dcd to your computer and use it in GitHub Desktop.
connectionFromArray helper for relay tests
export const connectionFromArray = <T extends any>(arr: T[] = []) => {
if (!arr || arr.length === 0) {
return {
edges: [],
count: 0,
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
},
};
}
return {
edges: arr.map((node) => ({ cursor: node?.id, node })),
count: arr.length,
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
},
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment