Skip to content

Commit 2f3deaa

Browse files
committed
fix: make PageInfo as a global type
It's fix problem when you use different schemaComposers and then merge it's instances manually.
1 parent f6a3602 commit 2f3deaa

File tree

2 files changed

+27
-56
lines changed

2 files changed

+27
-56
lines changed

src/types/connectionType.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,45 @@
33

44
import {
55
ListComposer,
6+
ObjectTypeComposer,
67
NonNullComposer,
78
upperFirst,
89
type SchemaComposer,
9-
type ObjectTypeComposer,
1010
} from 'graphql-compose';
1111

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+
1237
export function preparePageInfoType(
1338
schemaComposer: SchemaComposer<any>,
1439
name: string = 'PageInfo'
1540
): ObjectTypeComposer<any, any> {
1641
if (schemaComposer.has(name)) {
1742
return schemaComposer.getOTC(name);
1843
}
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);
3645
}
3746

3847
export function prepareEdgeType<TContext>(

src/utils/deepmerge.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)