Documentation on how to create a resolver with query filtering #28126
Replies: 2 comments 1 reply
-
Hi @jasonbiondo . I'm going to convert your issue to a discussion :) |
Beta Was this translation helpful? Give feedback.
-
You can do this with custom resolvers using https://www.gatsbyjs.com/docs/node-apis/#createResolvers Also in blog posts: Also given your description, something like this will probably work: // in gatsby-node
exports.createResolvers = ({ createResolvers }) => {
createResolvers({
NodeType: {
images: {
args: { limit: `Int` },
resolve: async (root, args, context, info) => {
const allImages = await info.originalResolver(root, args, context, info) || []
return args.limit ? allImages.slice(0, args.limit) : allImages
}
}
}
})
} |
Beta Was this translation helpful? Give feedback.
-
Can someone explain how to create a resolver for something like limiting the amount of images returned in query. Lets assume you have
node -> images -> src
and I want to do
node -> images(limit: 2) -> src
so only 2 images would be queryied via graphql. How can we create these subfilters? I. assume it's with a resolver but I see no example of this in the docs.
Beta Was this translation helpful? Give feedback.
All reactions