GraphQL : Get children of specific implementation

后端 未结 1 1050
时光取名叫无心
时光取名叫无心 2021-01-27 16:38

I\'m getting a GraphQL object with a \'children\' field. That field is of the type \'X\' and has two different implementations, \'Y\' and \'Z\'.

So when I\'m doing my qu

1条回答
  •  时光说笑
    2021-01-27 16:48

    What you are seeing is expected behavior. From the spec:

    Fragments can be defined inline within a selection set. This is done to conditionally include fields based on their runtime type.

    Type conditions like ... on Y are just a way to filter what fields are resolved based on the runtime type. They are not a way to filter the actual list of results. In fact, there is no built-in filtering in GraphQL.

    In order to filter a list to include only certain types (or based on any other condition), the field in question will need to have some kind of filter argument and resolver logic that uses it to actually do the filtering.

    If you're using a third-party API and the schema doesn't support filtering, then as a client there's not much you can do outside of processing the response after the fact.

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