我在手动调用Resolver.resolve时遇到问题
const createEntityGroupResolver = EntityGroupTC.getResolver('createOne')
const createEntityResolver = EntityTC.getResolver('createOne')
const entityGroupCreate = new Resolver({
name: 'entityGroupCreate',
type: createEntityGroupResolver.type,
args: createEntityGroupResolver.args,
resolve: async ({ source, args, context, info }) => {
const created = (await createEntityGroupResolver.resolve({ source, args, context, info })).record
console.log("created entityGroup : ", created, " from args: ", args)
const newArgs = {record:
{name: args.record.name, entityGroupId:created._id}}
args.record.entityGroupId=created._id
console.log("creating entity from args works: ", args, " but with newArgs it fails: ", newArgs)
await createEntityResolver.resolve({source, newAargs, context, info})
return created
}
});
此代码引发以下错误:
根据args创建实体:{记录:
{名称:'fsgd1',
fb: 'jgjhgf', web: 'kljh', city: 'jk', entityGroupId: 5bcf7ca2cd38080750b609f1 } } but with newArgs it fails: { record: { name: 'fsgd1', entityGroupId:
5bcf7ca2cd38080750b609f1}
graphQl错误:Entity.createOne 解析程序在args.record中需要至少一个值(节点:1872) [DEP0079]弃用警告:对象的自定义检查功能 通过.inspect()已弃用
对于神秘的原因,传递修改后的args参数有效
await createEntityResolver.resolve({source, args, context, info})
return created
我注意到args是用换行符记录的,而newArgs是内联记录的,我不明白为什么
答案 0 :(得分:0)
正如this post中的“ Pavel Chertorogov”所回答的那样,问题是我缺少了必须为args而不是newArgs的参数名称(因为我正在传递映射,而不是使用params调用函数)
我必须这样纠正: -等待createEntityResolver.resolve({source,newAargs,context,info}) +等待createEntityResolver.resolve({source,args:newArgs,context,info})