diff --git a/packages/graphql/src/schema/buildPaginatedListType.ts b/packages/graphql/src/schema/buildPaginatedListType.ts index 343fd28cba8..2a8a64c5d1f 100644 --- a/packages/graphql/src/schema/buildPaginatedListType.ts +++ b/packages/graphql/src/schema/buildPaginatedListType.ts @@ -10,11 +10,11 @@ export const buildPaginatedListType = (name, docType) => hasNextPage: { type: new GraphQLNonNull(GraphQLBoolean) }, hasPrevPage: { type: new GraphQLNonNull(GraphQLBoolean) }, limit: { type: new GraphQLNonNull(GraphQLInt) }, - nextPage: { type: new GraphQLNonNull(GraphQLInt) }, + nextPage: { type: GraphQLInt }, offset: { type: GraphQLInt }, page: { type: new GraphQLNonNull(GraphQLInt) }, pagingCounter: { type: new GraphQLNonNull(GraphQLInt) }, - prevPage: { type: new GraphQLNonNull(GraphQLInt) }, + prevPage: { type: GraphQLInt }, totalDocs: { type: new GraphQLNonNull(GraphQLInt) }, totalPages: { type: new GraphQLNonNull(GraphQLInt) }, }, diff --git a/test/graphql/int.spec.ts b/test/graphql/int.spec.ts index ab4cfbdd696..6006887fb77 100644 --- a/test/graphql/int.spec.ts +++ b/test/graphql/int.spec.ts @@ -104,5 +104,50 @@ describe('graphql', () => { expect(res.hyphenated_name).toStrictEqual('example-hyphenated-name') }) + + it('should not error because of non nullable fields', async () => { + await payload.delete({ collection: 'posts', where: {} }) + + // this is an array if any errors + const res_1 = await restClient + .GRAPHQL_POST({ + body: JSON.stringify({ + query: ` +query { + Posts { + docs { + title + } + prevPage + } +} + `, + }), + }) + .then((res) => res.json()) + expect(res_1.errors).toBeFalsy() + + await payload.create({ + collection: 'posts', + data: { title: 'any-title' }, + }) + + const res_2 = await restClient + .GRAPHQL_POST({ + body: JSON.stringify({ + query: ` +query { + Posts(limit: 1) { + docs { + title + } + } +} + `, + }), + }) + .then((res) => res.json()) + expect(res_2.errors).toBeFalsy() + }) }) })