首页 > 其他 > 详细

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

时间:2019-08-20 19:29:11      阅读:108      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!