I´m trying to customize a GraphQL schema:
type ModuleCourseEntityResponseCollection {
data: [ModuleCourseEntity!]!
meta: ResponseCollectionMeta!
}
By basically removing the “data” field and trying to only send an array with the objects I need, but instead it throws me an error while I´m following up this documentation about customizing GraphQL How to Extend and Build Custom Resolvers with Strapi v4:
Here´s my progress so far:
'use strict';
const {
afterCreate,
} = require('./api/profile/content-types/profile/lifecycles');
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');
extensionService.use(({ nexus }) => ({
typeDefs: `
type Query {
moduleCourses(
filters: ModuleCourseFiltersInput
pagination: PaginationArg = {}
sort: [String] = []
publicationState: PublicationState = LIVE):[ModuleCustomResponse]
}
type ModuleCustomResponse{
author: String
title: String
description_title: String
description_subtitle: String
description_module: String
time_duration: String
image: UploadFileEntityResponse
}
`,
resolvers: {
Query: {
moduleCourses: {
resolve: async (parent, args) => {
const { toEntityResponse } = strapi.service(
'plugin::graphql.format'
).returnTypes;
// console.log('parent:', parent);
// console.log('args:', args);
// console.log('context:', context);
const data = await strapi.services[
'api::module-course.module-course'
].find({
pagination: args.pagination.limit,
});
const response = toEntityResponse(data.results);
console.log(
'##################',
response,
'##################'
);
return response.value;
},
},
},
},
}));
},
async bootstrap({ strapi }) {
strapi.db.lifecycles.subscribe({
models: ['plugin::users-permissions.user'],
// your lifecycle hooks
async beforeCreate(event) {
const { params } = event;
//custom code
},
});
await boostrap();
},
};
Anyone knows how to solve this error?
System Information
- Strapi Version: 4.4.1
- Operating System: Windows 11
- Database: Postgres
- Node Version: v14.20.0
- NPM Version: 6.14.17
- Yarn Version: 1.22.19