
Wanna quickly point out that @paulkuhle solution isn’t working on Strapi v4.8.0
Paul’s solutions helped me a lot. This was the code I’m currently using:
in src/index.js
'use strict';
/** this is a test */
module.exports = {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register({ strapi }) {
const extensionService = strapi.plugin("graphql").service("extension");
const extension = () => ({
typeDefs: `
type Query {
faqQuestion(slug: String!): FaqQuestionEntityResponse
}
`,
resolvers: {
Query: {
faqQuestion: {
resolve: async (parent, args, context) => {
const { toEntityResponse } = strapi.service(
"plugin::graphql.format"
).returnTypes;
const data = await strapi.services["api::faq-question.faq-question"].find({
filters: { slug: args.slug },
});
const response = toEntityResponse(data.results[0]);
return response;
},
},
},
},
});
extensionService.use(extension);
},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {},
};
In Strapi’s latest patch v2.8.0 the code isn’t working anymore because ID is now required when querying for singular content type requests:
Field \"faqQuestion\" argument \"id\" of type \"ID!\" is required, but it was not provided.
don’t know why they did it, but I’m looking for a solution because this breaks my whole app… 