System Information
- **Strapi Version 4.5.0:
- **Operating System Ubuntu:
- **Database sql:
- **Node Version 16:
- **NPM Version 6.14:
- **Yarn Version unuse:
Hello,
I’am newbie to strapi. I was able to write lot of custom resolvers and to deport them outside of the index.ts file for purposes of code readability.
Now, want to create a custom mutation for create some complex and nested entity on Strapi. I’ll need to do that for complex creations needs. In order to begin, i’ve started to create a simple custom mutation.
Here the code i want to execute :
export default (strapi) => {
const extensionService = strapi.plugin("graphql").service("extension");
extensionService.use(({ strapi }) => ({
typeDefs: `
type Mutation {
createEmptyContract(contractName: String!): [Contract]
}
`,
resolvers: {
Mutation: {
createEmptyContract: {
resolve: async (_, args) => {
const contract = await strapi.entityService.create(
"api:contract.contract",
{
data: {
label: args.contractName,
},
},
);
return contract;
},
},
},
},
}));
};
I know that i can do that with native strapi endpoint, but in the futurei’ll need to do some more complex creation and i gonna need this kind of custom resolvers.
I get the following errors :
{
"errors": [
{
"message": "Cannot read properties of undefined (reading 'attributes')",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createEmptyContract"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot read properties of undefined (reading 'attributes')",
" at createComponents (/app/node_modules/@strapi/strapi/lib/services/entity-service/components.js:21:11)",
" at Object.create (/app/node_modules/@strapi/strapi/lib/services/entity-service/index.js:135:33)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Object.<anonymous> (/app/node_modules/@strapi/strapi/lib/services/entity-service/index.js:310:20)"
]
}
}
}
],
"data": {
"createEmptyContract": null
}
}
Does any one have an idea ?