GraphQL 字段作为函数 [英] GraphQL fields as a function
本文介绍了GraphQL 字段作为函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究 GraphQL
,在编写 GraphQLObjectType
的 fields
时,我对特定问题的不同实现有点困惑.
这两种实现有什么区别?
I am studying GraphQL
and I get a bit confused from different implementations on the specific issue when writing the fields
of a GraphQLObjectType
.
What is the difference between these two implementations?
1.
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: { // as object
echo: {
type: GraphQLString,
args: {
email: { type: EmailType }
},
resolve: (root, {email}) => {
return email;
}
}
}
})
});
var ComplicatedArgs = new GraphQLObjectType({
name: 'ComplicatedArgs',
fields: () => ({ // as function
complexArgField: {
type: GraphQLString,
args: {
complexArg: { type: ComplexInput }
},
}
}),
});
推荐答案
当你需要做循环引用时.
When you need to make a circular reference.
在这里寻找我的类似答案
Look for my similiar answer here
这篇关于GraphQL 字段作为函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文