Created
July 2, 2020 18:34
-
-
Save jgthms/951f17eb97791336cb00421569d3da60 to your computer and use it in GitHub Desktop.
Strapi GraphQL find single item by slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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