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. Go实战--golang中使用redis(redigo和go-redis/redis)

    开源库redigo的使用 github地址: https://github.com/garyburd/redigo 文档地址: http://godoc.org/github.com/garyburd ...

  2. AX 中临时表应用

    临时表,只要让表的Temporary属性设为yes就行. 今天写代码时发现,假如在一个循环里面把数据插入到临时表里, 假如没有在每次开始时没加clear的话,假如有个字段下一条没数据,会自动带到下一条 ...

  3. 使用 react 的 hooks 进行全局的状态管理

    使用 react 的 hooks 进行全局的状态管理 React 最新正式版已经支持了 Hooks API,先快速过一下新的 API 和大概的用法. // useState,简单粗暴,setState ...

  4. php 跳转页面

    header('location:./example.php'); header('refresh:2;url=./example.php');

  5. JQuery 的优先级

    1.使用最新的jQuery版本 2.用对选择器.   2.1 jquery最快的选择器是ID选择器:来源于js的getElementById()方法 注释:需要选择多个元素,必然涉及到Dom遍历和循环 ...

  6. "多层感知器"--MLP神经网络算法

    提到人工智能(Artificial Intelligence,AI),大家都不会陌生,在现今行业领起风潮,各行各业无不趋之若鹜,作为技术使用者,到底什么是AI,我们要有自己的理解. 目前,在人工智能中 ...

  7. 五、eureka客户端自动配置

    所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 前面的几篇文章中,我们从eureka Server端的角度看了看eureka的几个核心要 ...

  8. elementUI图片墙上传

    elementUI提供了照片墙上传的功能,我们直接拿来用. 以下是实现代码: <template> <div style="padding: 50px;"> ...

  9. 学习笔记之Google

    Google Pro Tip: Use Back-of-the-envelope-calculations to Choose the Best Design - High Scalability - ...

  10. jq的ajax方法

    相较与js异步对象的繁琐,jq的ajax对象结构更加清晰 一:ajax对象简述 ajax(Asynchronous JavaScript and XML),异步的xml和js对象,主要用于在不刷新全局 ...