[GraphQL] Query GraphQL Interface Types in GraphQL Playground
Posted answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[GraphQL] Query GraphQL Interface Types in GraphQL Playground相关的知识,希望对你有一定的参考价值。
Interfaces are similar to Unions in that they provide a mechanism for dealing with different types of data. However, an interface is more suited for data types that include many of the same fields. In this lesson, we will query different types of pets.
To follow along with these queries, go to the Pet Library GraphQL Playground.
Interface:
# Write your query or mutation here
query
totalPets,
availablePets,
checkedOutPets,
allAvailablePets
__typename,
...PetDetail,
# only related to CAT
... on Cat
sleepAmount
,
# only related to Rabbit
... on Rabbit
favoriteFood,
floppy
,
# only related to Stingray
... on Stingray
fast
fragment PetDetail on Pet
name,
weight,
status,
photo
thumb
Data return:
"data": "totalPets": 25, "availablePets": 23, "checkedOutPets": 2, "allAvailablePets": [ "__typename": "Cat", "name": "Biscuit", "weight": 10.2, "status": null, "photo": "thumb": "https://www.catis.life/placeholder/200" , "sleepAmount": 21 , ...
以上是关于[GraphQL] Query GraphQL Interface Types in GraphQL Playground的主要内容,如果未能解决你的问题,请参考以下文章
[GraphQL] Query a GraphQL API with graphql-request
如何在 .graphql 文件中编写 GraphQl Upsert Query
[GraphQL] Reuse Query Fields with GraphQL Fragments
[GraphQL] Filter Data Based on Query Arguments with GraphQL
<Query> vs graphql Hoc,这是在 react apollo 中将 graphql 查询与组件挂钩的最佳方法