Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL fields as a function

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 }
      },
    }
  }),
});
like image 586
itaied Avatar asked Sep 19 '16 18:09

itaied


1 Answers

When you need to make a circular reference.

Look for my similiar answer here

Dynamically creating graphql schema with circular references

like image 51
LordDave Avatar answered Oct 16 '22 17:10

LordDave