-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
issue: added to backlogissue: doc requestIssues that require adding new content, possibly with some prior researchIssues that require adding new content, possibly with some prior researchsource: Dev DocsPRs/issues targeting the Developer DocsPRs/issues targeting the Developer Docstarget: v4Documentation PRs/issues targeting content from docs.strapi.io (main branch).Documentation PRs/issues targeting content from docs.strapi.io (main branch).
Description
Summary
in backend-customization/
you have this example:
// path: ./src/api/restaurant/controllers/restaurant.js
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::restaurant.restaurant', ({ strapi }) => ({
// Method 1: Creating an entirely custom action
async exampleAction(ctx) {
try {
ctx.body = 'ok';
} catch (err) {
ctx.body = err;
}
},
// Method 2: Wrapping a core action (leaves core logic in place)
async find(ctx) {
// some custom logic here
ctx.query = { ...ctx.query, local: 'en' }
// Calling the default core action
const { data, meta } = await super.find(ctx);
// some more custom logic
meta.date = Date.now()
return { data, meta };
},
// Method 3: Replacing a core action
async findOne(ctx) {
const { id } = ctx.params;
const { query } = ctx;
const entity = await strapi.service('api::restaurant.restaurant').findOne(id, query);
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return this.transformResponse(sanitizedEntity);
}
});how to can we do the same for GraphQL? both adding a new method (exampleAction) and extending existing ones like find and findMany
Why is it needed?
I want to use GraphQL but can't figure it out, how to extend it.
in particular I'm interested in create a method to return an entity via slug with graphQL, whit a new custom method like getEntityBySlug(slug) that returns a single entity, and not using find(filters)
Suggested solution(s)
No response
Related issue(s)/PR(s)
No response
timohofmeijer, kenjyVincent-Sully, natTP and aaronLejeune
Metadata
Metadata
Labels
issue: added to backlogissue: doc requestIssues that require adding new content, possibly with some prior researchIssues that require adding new content, possibly with some prior researchsource: Dev DocsPRs/issues targeting the Developer DocsPRs/issues targeting the Developer Docstarget: v4Documentation PRs/issues targeting content from docs.strapi.io (main branch).Documentation PRs/issues targeting content from docs.strapi.io (main branch).