码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-08-20 18:52:54      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:resolve   use   less   ati   hat   define   inf   unit   mon   

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

 

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

标签:resolve   use   less   ati   hat   define   inf   unit   mon   

原文地址:https://www.cnblogs.com/Answer1215/p/11384642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!