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. nginx tar包安装 包含openssl,rewrite,stream,sticky 等模块

    最近需要使用nginx 但是发现有时缺少一些模块. 所以 在学习如何增加上相应的模块. 主要学习的网站: 沧海书生 Ansible爱好者 https://www.cnblogs.com/tssc/p/ ...

  2. qt 旧项目编译运行提示 “启动程序失败,路径或者权限错误?” 原因及解决方法

    qt 旧项目编译运行提示 "启动程序失败,路径或者权限错误?" 原因及解决方法 原因 Qt Creator在打开项目文件的同时会生成.pro.user文件,.pro.user文件叫 ...

  3. Python for循环生成列表

    一般Python for语句前不加语句,但我在机器学习实战中看到了这两条语句: featList = [example[i] for example in dataSet] classList = [ ...

  4. Python开发【第二章】:数据类型

    基本数据类型 一.整型 如: 18.73.84 整型具备如下功能: class int(object): """ int(x=0) -> int or long i ...

  5. 我们为什么要用redis

    Redis的5要点: 1.为什么要选择Redis:介绍Redis的使用场景与使用Redis的原因: 2.Redis常用命令总结:包括时间复杂度总结与具体数据类型在Redis内部使用的数据结构: 3.R ...

  6. java线程的五种状态

    五种状态 开始状态(new) 就绪状态(runnable) 运行状态(running) 阻塞状态(blocked) 结束状态(dead) 状态变化 1.线程刚创建时,是new状态 2.线程调用了sta ...

  7. 今日前端框架Vue学习笔记

    在线网页网址http://xingxunxinxi.com/StudentCourse/first.html代码 界面

  8. Django学习笔记(二)App创建之Model

    通过实例学习, 构建一个投票(Polls)Application, 目标结果包含两个site, 一个site用来显示投票问题以及投票结果(即将展示出来的网站), 另一个site用来管理Poll实例的增 ...

  9. element-ui 文件上传

    <el-form-item> <el-upload ref="upload" class="upload-demo" :action=&quo ...

  10. .NET 对文件和文件夹操作的介绍

    1 Directory和File类只包含静态方法,不能被实例化 2 DirectoryInfo和FileInfo他们是有状态的,需要被实例化 //构造函数初始化一个文件的路径 FileInfo myF ...