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": ,
"availablePets": ,
"checkedOutPets": ,
"allAvailablePets": [
{
"__typename": "Cat",
"name": "Biscuit",
"weight": 10.2,
"status": null,
"photo": {
"thumb": "https://www.catis.life/placeholder/200"
},
"sleepAmount":
},
... }

[GraphQL] Query GraphQL Interface Types in GraphQL Playground的更多相关文章

  1. [GraphQL] Add an Interface to a GraphQL Schema

    As we start building out more complex GraphQL schemas, certain fields start to repeat across differe ...

  2. 爬取LeetCode题目——如何发送GraphQL Query获取数据

    前言   GraphQL 是一种用于 API 的查询语言,是由 Facebook 开源的一种用于提供数据查询服务的抽象框架.在服务端 API 开发中,很多时候定义一个接口返回的数据相对固定,因此要获得 ...

  3. SpringBoot开发秘籍 - 集成Graphql Query

    概述 REST作为一种现代网络应用非常流行的软件架构风格受到广大WEB开发者的喜爱,在目前软件架构设计模式中随处可见REST的身影,但是随着REST的流行与发展,它的一个最大的缺点开始暴露出来: 在很 ...

  4. Go语言规格说明书 之 接口类型(Interface types)

    go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,介绍Go语言的  ...

  5. [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 ...

  6. [GraphQL] Use Arguments in a GraphQL Query

    In GraphQL, every field and nested object is able to take in arguments of varying types in order to ...

  7. [GraphQL] Query a GraphQL API with graphql-request

    To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation ...

  8. [GraphQL] Query Local and Remote Data in Apollo Link State

    In this lesson, you will learn how to query local and remote data in Apollo Link State in the same c ...

  9. [GraphQL] Mutations and Input Types

    Sometimes, you want to resues object type when doing mutation, you can use 'input' type to help: inp ...

随机推荐

  1. Eclipse设置每行的最大字符数

    Eclipse默认宽度是 120 个字符.如下图所示(提示:格式化快捷键Ctrl + Shift + F): 设置步骤如下: 菜单栏倒数第二项,选择Window 下拉栏最后一项,选择Preferenc ...

  2. 几个有益的 CSS 小知识

    样式的顺序 CSS 代码:   HTML 代码:   记得之前这是一道比较火的 CSS 考题,当时好像是有不少的人答错(30% 以上) 答案你们应该是知道的. 可以这样提升 CSS 性能 后代选择器 ...

  3. redis列表数据类型---list

    一.概述 redis列表是简单的字符串列表,按照插入顺序排序 可以添加一个元素到列表的头部(左边)或者尾部(右边) 一个列表最多可以包含2^32-1个元素(每个列表超过40亿个元素). 二.redis ...

  4. ASP.NET MVC 5 伪静态之支持*.html路由

    参考了例子 到自己实践还是有不少坑要踩,这种文章,你说它好还是不好呢 注意这里的版本是ASP.NET MVC 5 首页的URL为  http://localhost:58321/index.html  ...

  5. Sublim text 3 同步 eclipse 快捷键

    首选项>按键绑定>用户 配置内容(注意为JSON格式!) [ { "keys": ["shift+enter"], "command&qu ...

  6. vue+iview tables多个分页实现

    如果一个页面有多个分页那么可以把每个page和pageSize放到一个对象中,如下: dataList: { name: 'dataList', // 方便取到dataList对象 id: null, ...

  7. 查询并批量插入数据的Sql命令

    INSERT INTO student(id,xuesheng,yuwen,shuxue,yingyu) SELECT id,xuesheng,yuwen,shuxue,yingyu FROM stu ...

  8. Django配置websocket请求接口

    1.settings.py INSTALLED_APPS = [ '...', 'channels', '...', ] ASGI_APPLICATION = 'server.routing.appl ...

  9. CSS选取第一个、最后一个、偶数、奇数、第n个标签元素

    1.first-child first-child表示选择列表中的第一个标签.例如:li:first-child{background:#fff} 2.last-child last-child表示选 ...

  10. OpenStack kilo版(2) keystone部署

    部署在controller节点 配置数据库 MariaDB [(none)]> CREATE DATABASE keystone; Query OK, 1 row affected (0.00 ...