Having a custom page slug using strapi5, I want to be able to fetch data with GraphQL by slug, and I made the following changes
import type { Core } from '@strapi/strapi';
export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register({ strapi }: { strapi: Core.Strapi }) {
const extensionService = strapi.plugin('graphql').service('extension');
const extension = ({ nexus }) => ({
typeDefs: `
type Query {
documentId: ID
page(slug: String): Page
}
`,
resolvers: {
Query: {
page: {
resolve: async (parent, args, context) => {
const { toEntityResponse } = strapi.service(
"plugin::graphql.format"
).returnTypes;
const data = await strapi.services["api::page.page"].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 }: { strapi: Core.Strapi } */) { },
};
```
However documentId is required field. How can I make that optional?
<i>This topic has been created from a Discord post (1237825913304125490) to give it more visibility.
It will be on Read-Only mode here.
<a href="https://discord.com/channels/811989166782021633/1237825913304125490/1237825913304125490">Join the conversation on Discord</a></i>