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. Quartz.Net—配置化

    Schedule配置 线程数量 如果一个Schedule中有很多任务,这样默认的10个线程就不够用了. 有很多种方法配置线程的个数. 工厂构造函数 webfonfig quartzconfig 环境变 ...

  2. SecureCRT系列:生成公私钥

    SecureCRT下载地址:http://www.portablesoft.org/securecrt-securefx-legacy-versions/1.打开我们的SecureCRT客户端,点击t ...

  3. ubuntu mysql5.7设置Open Files Limit

    目的:解决Too many open files异常 方式:设置Open Files Limit 环境:(MySQL)Server version: 5.7.27-0ubuntu0.16.04.1 ( ...

  4. 开始使用 Manjaro(添加源+字体渲染去模糊+软件安装+优化配置+常见错误)(30)

    1. 添加 archlinux 镜像源 1. 步骤一 向 /etc/pacman.d/mirrorlist 中添加国内镜像地址 1.1 方法1:自动添加 1. 输入如下命令查看国内镜像源,并按质量排序 ...

  5. 简单的鼠标操作<一个填充格子的小游戏>

    #include "graphics.h" #include "conio.h" void main(){ // 初始化界面 initgraph(, ); ; ...

  6. go语言的3个包——strconv、os.Args、flag

    1. strconv包: 2. os.Args: 获取运行程序时给出的参数,可以通过os包来实现.看代码: package main import ( "fmt" "os ...

  7. Android--Fragment嵌套的问题

    项目中遇到Fragment嵌套应用的问题 子Fragment中要用getChildFragmentManager()方法获取FragmentManager,否则会出问题!

  8. git 修改注释

    原文:https://www.jianshu.com/p/098d85a58bf1 修改最后一条注释: git commit --amend 如果已经推送到远程,强制push到远程仓库: git pu ...

  9. springboot2.0+mybatis多数据源集成

    最近在学springboot,把学的记录下来.主要有springboot2.0+mybatis多数据源集成,logback日志集成,springboot单元测试. 一.代码结构如下 二.pom.xml ...

  10. Java LowerBound

    Java LowerBound /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternational ...