GraphQL query: only include field if not null

前端 未结 2 473
独厮守ぢ
独厮守ぢ 2020-12-30 01:43

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

Given the query



        
相关标签:
2条回答
  • 2020-12-30 02:27

    You can use this ES6 syntax in front-end:

    Object.keys(data).forEach((key) => (data[key] == null) && delete data[key]);
    
    0 讨论(0)
  • 2020-12-30 02:34

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

    0 讨论(0)
提交回复
热议问题