Created
June 2, 2021 15:16
-
-
Save sibelius/1d7707f4a0c10b0dce2f105fb3a81dcd to your computer and use it in GitHub Desktop.
connectionFromArray helper for relay tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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