[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
    }
  }
}
原文地址:https://www.cnblogs.com/Answer1215/p/11384642.html