我正在try 扩展Keystone 6中的一个Mutations ,但仅仅是让标准的DB更新在一个定制的Mutations 解析器中工作就有很大的困难;使用标准的Keystone样板并添加了一个新的集合/列表.
在示例here之后,我将custom-schema.ts
与生成的schema.graphql
进行了匹配
Schema.graph ql(简体):
type Dog {
id: ID!
name: String
}
input DogWhereUniqueInput {
id: ID
}
input DogUpdateInput {
name: String
}
type Mutation {
updateDog(
where: DogWhereUniqueInput!
data: DogUpdateInput!
): Dog
}
自定义-架构.ts:
import { graphQLSchemaExtension } from '@keystone-6/core';
import { Context } from '.keystone/types';
export const extendGraphqlSchema = graphQLSchemaExtension<Context>({
typeDefs: `
type Mutation {
""" update a dog """
updateDog(
where: DogWhereUniqueInput!
data: DogUpdateInput!
): Dog
}
`,
resolvers: {
Mutation: {
updateDog: async (root, { where, id }, context) => {
try {
const response = await context.db.Dog.updateOne({
where: { id },
data: { name: 'updated name'}
});
return response;
} catch (updateError: any) {
throw updateError;
}
}}
}
},
);
Keystone.ts:
import { extendGraphqlSchema } from './custom-schema';
// ...
export default withAuth(
config({
db: {
provider: 'sqlite',
url: 'file:./keystone.db',
},
ui: {
isAccessAllowed: (context) => !!context.session?.data,
},
lists,
session,
extendGraphqlSchema,
})
);
当我从(样板)UI触发更新时,我从Catch Error处理程序反复收到此错误.同样的事情也发生在GraphQL操场上.我真的很难理解发生了什么,为什么解析器会收到垃圾邮件并生成这个错误.
RangeError: Maximum call stack size exceeded
at isLeafType (.../poc/node_modules/graphql/type/definition.js:247:20)
at coerceInputValueImpl (.../poc/node_modules/graphql/utilities/coerceInputValue.js:122:34)
为什么会发生这种情况,如何解决?我是不是漏掉了什么明显的东西?