问题描述
嘿,我正在尝试使自定义突变在具有“外部”反应、next 和 apollo 前端的 keystone-next 中工作,但是从前端调用突变时遇到问题,但从前端调用突变时却没有问题Keystone api 浏览器。突变真的很简单。
架构扩展:
export const extendedGqlSchema = graphQLSchemaExtension({
typeDefs: graphql`
type Mutation {
testAvailability(name: String): String
}
`,resolvers: {
Mutation: {
testAvailability: testAvailability,},});
解析器函数(不同的文件):
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";
};
有效的原始 http 请求正文是:
{
"operationName": null,"variables": {},"query": "mutation {\n testAvailability(name: \"Eve\")\n}\n"
}
而原始 http 前端生成的请求正文如下所示:
{
"operationName": "testAvailability","variables": {
"name": "Eve"
},"query": "mutation testAvailability($name: String) {\n testAvailability(name: $name) {\n name\n __typename\n }\n}\n"
}
当我使用完全相同的标头从 Postman 运行这些请求时,第一个仍然有效,而第二个仍然无效(没有身份验证等)。 400 bad request response 返回的错误如下:
{
"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)"
]
}
}
}
]
}
我错过了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)