We've made this graphql resolever for payload, is there any way we could implement a hasMore return variable so we can know if a collection has more data / it doesnt ?
import { GraphQLExtension } from "payload/config";
const RtaGalleryImagesByCategories: GraphQLExtension = (GraphQL, payload) => {
return {
type: new GraphQL.GraphQLObjectType({
name: "RtaGalleryImagesByCategories",
fields: {
docs: {
type: new GraphQL.GraphQLList(
payload.collections["rtaGalleryImages"].graphQL.type
),
},
},
}),
args: {
categoryIds: {
type: new GraphQL.GraphQLList(GraphQL.GraphQLInt),
},
locale: {
type: GraphQL.GraphQLString,
},
fallbackLocale: {
type: GraphQL.GraphQLString,
},
sort: {
type: GraphQL.GraphQLString,
},
limit: {
type: GraphQL.GraphQLInt,
},
},
resolve: async (
_: unknown,
{
categoryIds = [],
locale = payload.config.localization &&
payload.config.localization.defaultLocale,
fallbackLocale = payload.config.localization &&
payload.config.localization.defaultLocale,
sort = "id",
limit = 10,
}: {
categoryIds: number[];
locale: string;
fallbackLocale: string;
sort: string;
limit: number;
}
) => {
const data = await payload.find({
collection: "rtaGalleryImages",
depth: 0,
locale: locale,
fallbackLocale: fallbackLocale,
sort: sort,
limit: limit,
where: {
and: [
{
"categories.id": {
in: categoryIds,
},
},
],
},
});
return data;
},
};
};
export default RtaGalleryImagesByCategories;Hmm, wouldnt you check the index of the last returned item versus the total?
And how do I get the total ?
In all the queries where I need this reslover I limit the number of queries and I filter by category
I looked that the default payload resolver has something called hasNextPage but I have no idea how to implement that
All find queries have pagination
Which should provide a hasNextPage prop
should be on your data object
This is the query that uses our custom resolver
With the payload resolver it works but I cant filter the categories thats why we made our own resolver
hmm
Ill have to revisit this one because im not great with graphql. I'm going to ping
@858693520012476436when they are on they may provide better insight
Thanks
Ohh i see
graphql is really finnicky
but here in your type
type: new GraphQL.GraphQLObjectType({
name: "RtaGalleryImagesByCategories",
fields: {
docs: {
type: new GraphQL.GraphQLList(
payload.collections["rtaGalleryImages"].graphQL.type
),
},
},
}),where you have
docsnext to it add any other fields you want and give it
typefrom the GraphQL constructor...ill be honest that its not easy so you'll need to do a bit of trial and error to get it right
then in your resolver when you return
docsalso return in the same object the other fields and they need to be of compatible types
Figured it out, this is what we have now, thanks
type: new GraphQL.GraphQLObjectType({
name: "RtaGalleryImagesByCategories",
fields: {
docs: {
type: new GraphQL.GraphQLList(
payload.collections["rtaGalleryImages"].graphQL.type
),
},
totalDocs: {
type: GraphQL.GraphQLInt,
},
totalPages: {
type: GraphQL.GraphQLInt,
},
hasPrevPage: {
type: GraphQL.GraphQLBoolean,
},
hasNextPage: {
type: GraphQL.GraphQLBoolean,
},
},
}),Star
Discord
online
Get dedicated engineering support directly from the Payload team.