Hi!
Using v 4.17.0
of Strapi I’m trying to use custom middleware for my GraphQL mutations, I have this:
....
'Mutation.updateManifestEntry': {
middlewares: [
'api::manifest-entry.manifest-entry-log-middleware',
async (next, parent, args, context, info) => {
console.log('This is a test!')
return next(parent, args, context, info);
},
]
},
....
And this is my file src/api/manifest-entry/middlewares/manifestEntryLogMiddleware.ts
:
import { Strapi } from "@strapi/strapi";
export default (options, { strapi: Strapi }) => {
return async (next, parent, args, context, info) => {
console.log('manifest-entry-log-middleware.ts')
return next(parent, args, context, info)
};
};
It clearly states this in the docs:
The only difference between the GraphQL and REST implementations is that the
config
key becomesoptions
.
But clearly thats not working as I get this back:
[
{
"message": "Cannot destructure property 'strapi' of 'undefined' as it is undefined.",
"locations": [
{
"line": 3,
"column": 3
}
],
"path": [
"updateManifestEntry"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot destructure property 'strapi' of 'undefined' as it is undefined.",
" at exports.default (/Users/boriskamp/Documents/bk-development/todays-portal-strapi/dist/src/api/manifest-entry/middlewares/manifestEntryLogMiddleware.js:3:39)",
" at /Users/boriskamp/Documents/bk-development/todays-portal-strapi/node_modules/@strapi/plugin-graphql/dist/server/index.js:249:51",
" at fieldDefinition.resolve (/Users/boriskamp/Documents/bk-development/todays-portal-strapi/node_modules/@strapi/plugin-graphql/dist/server/index.js:274:42)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
]
}
}
}
]
So what am I doing wrong here and how can we make this more clear in the docs?