GraphQL query: include only field, if not null

Does GraphQL have the ability for the client to tell the server that it wants a field only if this field is not null ?

Given the request

 query HeroAndFriends { hero { name friends { name } } } 

The answer should look like this:

 { "data": { "hero": { "friends": [ { "name": "Luke Skywalker" }, { "name": "Han Solo" }, { "name": "Leia Organa" } ] } } } 

instead

 { "data": { "hero": { "name": null, "friends": [ { "name": "Luke Skywalker" }, { "name": "Han Solo" }, { "name": "Leia Organa" } ] } } } 

Is this possible without breaking GraphQL specifications?

+8
graphql
source share
1 answer

As far as I know, this is not possible, directives like @skip and @include. Directives, but they need a variable, I think you can make your case with the graphql command to extend the directives to include only the field if it is not empty.

+4
source share

All Articles