From 441b94dc0c1113d9bc6b4048a5728036f941122a Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 23 Apr 2025 20:32:47 +0300 Subject: [PATCH 1/3] fix(graphql): `nextPage` and `prevPage` are non nullable even though they can be `null` in some cases --- .../src/schema/buildPaginatedListType.ts | 4 +-- test/graphql/int.spec.ts | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) 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..89029bc4993 100644 --- a/test/graphql/int.spec.ts +++ b/test/graphql/int.spec.ts @@ -104,5 +104,30 @@ 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: {} }) + + //no posts + const errorsOrDataNext = await restClient + .GRAPHQL_POST({ + body: JSON.stringify({ + query: ` +query { + Posts { + docs { + title + } + } +} + `, + }), + }) + .then((res) => res.json()) + // array if any errors + expect(Array.isArray(errorsOrDataNext)).toBeFalsy() + expect(Array.isArray(errorsOrDataNext.data.Posts.docs)).toBeTruthy() + expect(errorsOrDataNext.data.Posts.docs).toHaveLength(0) + }) }) }) From dc86691556759516a83aaa843b0b9d0f398fc33a Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 23 Apr 2025 20:44:53 +0300 Subject: [PATCH 2/3] test more --- test/graphql/int.spec.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/test/graphql/int.spec.ts b/test/graphql/int.spec.ts index 89029bc4993..6006887fb77 100644 --- a/test/graphql/int.spec.ts +++ b/test/graphql/int.spec.ts @@ -108,8 +108,8 @@ describe('graphql', () => { it('should not error because of non nullable fields', async () => { await payload.delete({ collection: 'posts', where: {} }) - //no posts - const errorsOrDataNext = await restClient + // this is an array if any errors + const res_1 = await restClient .GRAPHQL_POST({ body: JSON.stringify({ query: ` @@ -118,16 +118,36 @@ query { docs { title } + prevPage } } `, }), }) .then((res) => res.json()) - // array if any errors - expect(Array.isArray(errorsOrDataNext)).toBeFalsy() - expect(Array.isArray(errorsOrDataNext.data.Posts.docs)).toBeTruthy() - expect(errorsOrDataNext.data.Posts.docs).toHaveLength(0) + 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() }) }) }) From 5211f765ab9e14bdb93f4e1b76ec55f8654563b9 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Thu, 24 Apr 2025 00:16:20 +0300 Subject: [PATCH 3/3] empty