Skip to content

fix(graphql): nextPage and prevPage are non nullable even though they can be null sometimes #12201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/graphql/src/schema/buildPaginatedListType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
},
Expand Down
45 changes: 45 additions & 0 deletions test/graphql/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
Loading