|
3 | 3 |
|
4 | 4 | import {
|
5 | 5 | ListComposer,
|
| 6 | + ObjectTypeComposer, |
6 | 7 | NonNullComposer,
|
7 | 8 | upperFirst,
|
8 | 9 | type SchemaComposer,
|
9 |
| - type ObjectTypeComposer, |
10 | 10 | } from 'graphql-compose';
|
11 | 11 |
|
| 12 | +// This is required due compatibility with old client code bases |
| 13 | +const globalPageInfoTypes = {}; |
| 14 | + |
| 15 | +function createGlobalPageInfoType(name: string) { |
| 16 | + if (!globalPageInfoTypes[name]) { |
| 17 | + globalPageInfoTypes[name] = ObjectTypeComposer.createTemp(` |
| 18 | + """Information about pagination in a connection.""" |
| 19 | + type ${name} { |
| 20 | + """When paginating forwards, are there more items?""" |
| 21 | + hasNextPage: Boolean! |
| 22 | + |
| 23 | + """When paginating backwards, are there more items?""" |
| 24 | + hasPreviousPage: Boolean! |
| 25 | +
|
| 26 | + """When paginating backwards, the cursor to continue.""" |
| 27 | + startCursor: String |
| 28 | +
|
| 29 | + """When paginating forwards, the cursor to continue.""" |
| 30 | + endCursor: String |
| 31 | + } |
| 32 | + `); |
| 33 | + } |
| 34 | + return globalPageInfoTypes[name]; |
| 35 | +} |
| 36 | + |
12 | 37 | export function preparePageInfoType(
|
13 | 38 | schemaComposer: SchemaComposer<any>,
|
14 | 39 | name: string = 'PageInfo'
|
15 | 40 | ): ObjectTypeComposer<any, any> {
|
16 | 41 | if (schemaComposer.has(name)) {
|
17 | 42 | return schemaComposer.getOTC(name);
|
18 | 43 | }
|
19 |
| - |
20 |
| - return schemaComposer.createObjectTC(` |
21 |
| - """Information about pagination in a connection.""" |
22 |
| - type ${name} { |
23 |
| - """When paginating forwards, are there more items?""" |
24 |
| - hasNextPage: Boolean! |
25 |
| - |
26 |
| - """When paginating backwards, are there more items?""" |
27 |
| - hasPreviousPage: Boolean! |
28 |
| -
|
29 |
| - """When paginating backwards, the cursor to continue.""" |
30 |
| - startCursor: String |
31 |
| -
|
32 |
| - """When paginating forwards, the cursor to continue.""" |
33 |
| - endCursor: String |
34 |
| - } |
35 |
| - `); |
| 44 | + return createGlobalPageInfoType(name); |
36 | 45 | }
|
37 | 46 |
|
38 | 47 | export function prepareEdgeType<TContext>(
|
|
0 commit comments