You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to unset GraphQLObjectType's field by not providing field from resolve function. My expected result would be that when I'm querying that field it would be not set (because resolve gave undefined). Example what I mean, I have type field "test" on root query witch is type Test like so: type: new GraphQLObjectType({ name: 'Test', fields: { testField: { type: GraphQLString } } }),
And resolve function for it like so: resolve: () => { return { }; },
While querying like:
{test{testField}}
I'm expecting to get result: { "data": { "test": {} } } But actually I get
{"data": {"test": {"testField": null}}}
Is there a reason why graphQL adds nulls?
The text was updated successfully, but these errors were encountered:
So I only can speak for Sangria, the Scala implementation, there it would be the same.
To understand that behavior, you need to know 2 things:
The Resolver works top down
null is the undefined or None of GraphQL
The query defines the structure of the response
So the resolver goes top down and looks for test, when test is not there because you didn't provide it in {}, the resolver automatically sets all child fields to null.
That is actually expected behavior as a query should always specify the structure of the response.
A client that does this query must be able to assume the fields data.test.testField, otherwise the whole idea of GraphQL wouldn't make sense 😃
When we would just return "data": { "test" : {} } the whole query doesn't make sense as a client now cannot trust the GraphQL typesystem anymore.
I hope that helped
Hello.
I'm trying to unset GraphQLObjectType's field by not providing field from resolve function. My expected result would be that when I'm querying that field it would be not set (because resolve gave undefined). Example what I mean, I have type field "test" on root query witch is type Test like so:
type: new GraphQLObjectType({ name: 'Test', fields: { testField: { type: GraphQLString } } }),
And resolve function for it like so:
resolve: () => { return { }; },
While querying like:
I'm expecting to get result:
{ "data": { "test": {} } }
But actually I getIs there a reason why graphQL adds nulls?
The text was updated successfully, but these errors were encountered: