gpt4 book ai didi

javascript - GraphQL 字段作为函数

转载 作者:行者123 更新时间:2023-12-02 18:53:55 25 4
gpt4 key购买 nike

我正在研究 GraphQL,在编写 GraphQLObjectTypefields 时,我对特定问题的不同实现感到有点困惑。< br/>这两种实现有什么区别?

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 }
    },
    }
    }),
    });

    最佳答案

    当您需要进行循环引用时。

    在这里寻找我的类似答案

    Dynamically creating graphql schema with circular references

    关于javascript - GraphQL 字段作为函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39579416/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com