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
Dynamically creating graphql schema with circular references
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With