zl程序教程

您现在的位置是:首页 >  其它

当前栏目

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

in of Using Query multiple types union GraphQL
2023-09-14 09:00:48 时间

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
    }
  }
}