Skip to content

Instantly share code, notes, and snippets.

@jgthms
Created July 2, 2020 18:34
Show Gist options
  • Save jgthms/951f17eb97791336cb00421569d3da60 to your computer and use it in GitHub Desktop.
Save jgthms/951f17eb97791336cb00421569d3da60 to your computer and use it in GitHub Desktop.
Strapi GraphQL find single item by slug
const { sanitizeEntity } = require('strapi-utils');
module.exports = {
query: `
categoryBySlug(slug: String!): Category
`,
resolver: {
Query: {
categoryBySlug: {
resolverOf: 'Category.findOne',
async resolver(_, { slug }) {
const entity = await strapi.services.category.findOne({ slug });
return sanitizeEntity(entity, { model: strapi.models.category });
},
},
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment