Skip to content

Commit

Permalink
fix: make PageInfo as a global type
Browse files Browse the repository at this point in the history
It's fix problem when you use different schemaComposers and then merge it's instances manually.
  • Loading branch information
nodkz committed Apr 29, 2019
1 parent f6a3602 commit 2f3deaa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 56 deletions.
45 changes: 27 additions & 18 deletions src/types/connectionType.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,45 @@

import {
ListComposer,
ObjectTypeComposer,
NonNullComposer,
upperFirst,
type SchemaComposer,
type ObjectTypeComposer,
} from 'graphql-compose';

// This is required due compatibility with old client code bases
const globalPageInfoTypes = {};

function createGlobalPageInfoType(name: string) {
if (!globalPageInfoTypes[name]) {
globalPageInfoTypes[name] = ObjectTypeComposer.createTemp(`
"""Information about pagination in a connection."""
type ${name} {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!
"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!
"""When paginating backwards, the cursor to continue."""
startCursor: String
"""When paginating forwards, the cursor to continue."""
endCursor: String
}
`);
}
return globalPageInfoTypes[name];
}

export function preparePageInfoType(
schemaComposer: SchemaComposer<any>,
name: string = 'PageInfo'
): ObjectTypeComposer<any, any> {
if (schemaComposer.has(name)) {
return schemaComposer.getOTC(name);
}

return schemaComposer.createObjectTC(`
"""Information about pagination in a connection."""
type ${name} {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!
"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!
"""When paginating backwards, the cursor to continue."""
startCursor: String
"""When paginating forwards, the cursor to continue."""
endCursor: String
}
`);
return createGlobalPageInfoType(name);
}

export function prepareEdgeType<TContext>(
Expand Down
38 changes: 0 additions & 38 deletions src/utils/deepmerge.js

This file was deleted.

0 comments on commit 2f3deaa

Please sign in to comment.