aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils/graphql
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-24 20:00:08 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-27 14:47:51 +0100
commitf111685c5886f3e77edfd3621c98d8ac1b9bcce4 (patch)
tree62a541fe3afeb64bf745443706fbfb02e96c5230 /tests/utils/graphql
parentbee515641cb144be9a855ff2cac258d2fedab21d (diff)
refactor(services, types): reorganize GraphQL fetchers and data types
The Typescript mapped types was useful for autocompletion in fetchers but their are harder to maintain. I think it's better to keep each query close to its fetcher to have a better understanding of the fetched data. So I: * colocate queries with their own fetcher * colocate mutations with their own mutator * remove Typescript mapped types for queries and mutations * move data convertors inside graphql services * rename most of data types and fetchers
Diffstat (limited to 'tests/utils/graphql')
-rw-r--r--tests/utils/graphql/connections.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/utils/graphql/connections.ts b/tests/utils/graphql/connections.ts
index f38fa59..dc4bfc6 100644
--- a/tests/utils/graphql/connections.ts
+++ b/tests/utils/graphql/connections.ts
@@ -1,4 +1,9 @@
-import type { EdgesResponse, GraphQLEdges, Maybe } from '../../../src/types';
+import type {
+ GraphQLConnection,
+ GraphQLEdge,
+ Maybe,
+ Nullable,
+} from '../../../src/types';
import { CONFIG } from '../../../src/utils/config';
/**
@@ -8,7 +13,7 @@ import { CONFIG } from '../../../src/utils/config';
* @param {number} offset - The offset.
* @returns {Array<Edge<T>>} The edges.
*/
-export const getEdges = <T>(data: T[], offset: number): GraphQLEdges<T>[] =>
+export const getEdges = <T>(data: T[], offset: number): GraphQLEdge<T>[] =>
data.map((singleData, index) => {
const currentItemNumber = index + 1;
@@ -21,7 +26,7 @@ export const getEdges = <T>(data: T[], offset: number): GraphQLEdges<T>[] =>
type GetConnectionProps<T> = {
data: Maybe<T[]>;
first: Maybe<number>;
- after: Maybe<string>;
+ after: Maybe<Nullable<string>>;
};
/**
@@ -37,7 +42,7 @@ export const getConnection = <T>({
after,
data = [],
first = CONFIG.postsPerPage,
-}: GetConnectionProps<T>): EdgesResponse<T> => {
+}: GetConnectionProps<T>): GraphQLConnection<T> => {
const afterInt = after ? Number(after.replace('cursor', '')) : 0;
const edges = getEdges(data.slice(afterInt, afterInt + first), afterInt);
const endCursor =
@@ -47,7 +52,9 @@ export const getConnection = <T>({
edges,
pageInfo: {
endCursor,
+ hasPreviousPage: typeof after !== 'undefined',
hasNextPage: data.length - afterInt > first,
+ startCursor: after ?? 'cursor1',
total: data.length,
},
};