GraphQL 字段作为函数 [英] GraphQL fields as a function

查看:16
本文介绍了GraphQL 字段作为函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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架构

这篇关于GraphQL 字段作为函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆