[GraphQL] Query Lists of Multiple Types using a Union in GraphQL

Unions are used when we want a GraphQL field or list to handle multiple types of data. With a Union Type, we can define a field that could resolve completely different types of data. In this lesson, we will write a query that obtains a list of different pet types

 

 

Unit type, we cannot use common field in query, I have to write in fragment:

# Write your query or mutation here
query {
  familyPets {
    __typename,
    ... on Cat {
      name
    },
    ... on Dog {
      name
    }
  }
}

 

posted @ 2019-08-20 18:06  Zhentiw  阅读(205)  评论(0编辑  收藏  举报