Hello, I am currently working on setting up a custom mutation in keystone-next with an "external" react, next & apollo frontend. However, I am encountering issues when calling the mutation from the frontend, even though it works fine when called from the Keystone api explorer. The mutation itself is quite simple.
Here is the schema extension:
export const extendedGqlSchema = graphQLSchemaExtension({
typeDefs: graphql`
type Mutation {
testAvailability(name: String): String
}
`,
resolvers: {
Mutation: {
testAvailability: testAvailability,
},
},
});
The resolver function (in a different file) looks like this:
export const testAvailability = (
root: any,
{ name }: { name: string },
context: KeystoneContext
): string => {
if (context) {
return new Date().toUTCString() + ": Hi " + name + ", I'm here!";
}
return new Date().toUTCString() + ": No context";
};
The raw http request body that works is as follows:
{
"operationName": null,
"variables": {},
"query": "mutation {\n testAvailability(name: \"Eve\")\n}\n"
}
On the other hand, the raw http frontend generated request body looks like this:
{
"operationName": "testAvailability",
"variables": {
"name": "Eve"
},
"query": "mutation testAvailability($name: String) {\n testAvailability(name: $name) {\n name\n __typename\n }\n}\n"
}
When running these requests from Postman with the exact same headers, the first one still works while the second does not (authentication etc. may be a factor). The error received in the 400 bad request response is:
{
"errors": [
{
"message": "Cannot assign to read only property 'path' of object '#<Object>'",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot assign to read only property 'path' of object '#<Object>'",
" at formatError (%ProjectPath%\backend\node_modules\@keystone-next\keystone\dist\createApolloServer-231615cf.cjs.dev.js:82:24)",
" at %ProjectPath%\\backend\\node_modules\\apollo-server-errors\\src\\index.ts:287:28",
" at Array.map (<anonymous>)",
" at Object.formatApolloErrors (%ProjectPath%\\backend\\node_modules\\apollo-server-errors\\src\\index.ts:285:25)",
" at formatErrors (%ProjectPath%\\backend\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:665:12)",
" at %ProjectPath%\\backend\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:649:15",
" at Generator.next (<anonymous>)",
" at fulfilled (%ProjectPath%\\backend\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:5:58)",
" at runMicrotasks (<anonymous>)",
" at processTicksAndRejections (internal/process/task_queues.js:93:5)"
]
}
}
}
]
}
I'm trying to figure out what might be missing or causing this issue. Any insights would be appreciated!