Fragments are selection sets that can be used across multiple queries. They allow you to refactor redundant selection sets, and they are essential when querying unions or interface types. In this lesson, we will improve our query logic by creating a fragment for the activity selection set.

To follow along with these queries, go to the Pet Library GraphQL Playground.

query Pet {
petById(id:"S-2") {
name,
weight,
photo {
thumb
},
status,
inCareOf {
name
}
}
allPets(category:RABBIT){
name,
weight,
photo {
thumb
},
status,
inCareOf {
name,
username
}
}
}

We can reuse part of query with fragement:

query Pet {
petById(id:"S-2") {
...PetDetail,
inCareOf {
...CustomerDetail
}
}
allPets(category:RABBIT){
...PetDetail,
inCareOf {
...CustomerDetail
}
}
} fragment CustomerDetail on Customer {
name,
username
} fragment PetDetail on Pet {
name,
weight,
photo {
thumb
},
status,
}

[GraphQL] Reuse GraphQL Selection Sets with Fragments的更多相关文章

  1. [GraphQL] Use GraphQL's List Type for Collections

    In order to handle collections of items in a GraphQL Schema, GraphQL has a List Type. In this video, ...

  2. [GraphQL] Reuse Query Fields with GraphQL Fragments

    A GraphQL fragment encapsulates a collection of fields that can be included in queries. In this vide ...

  3. 让ASP.NET Core支持GraphQL之-GraphQL的实现原理

    众所周知RESTful API是目前最流行的软件架构风格之一,它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制. RESTful的优越性是毋庸置疑 ...

  4. [GraphQL] Use GraphQL's Object Type for Basic Types

    We can create the most basic components of our GraphQL Schema using GraphQL's Object Types. These ty ...

  5. GraphQL ---02 GraphQL和C#结合的实战项目

    本文章是介绍和记录如何创建GraphQL项目,以及如何使用GraphQL进行数据的相关操作.项目参照GraphQL .Net 的官方文档进行实践 一.项目结构: 为了更好的和原有的项目结合在一起,尽可 ...

  6. [GraphQL] Query GraphQL Interface Types in GraphQL Playground

    Interfaces are similar to Unions in that they provide a mechanism for dealing with different types o ...

  7. graphql 新API 开发方式

    我们知道 GraphQL 使用 Schema 来描述数据,并通过制定和实现 GraphQL 规范 定义了支持 Schema 查询的 DSQL (Domain Specific Query Langua ...

  8. [转] Initial Impressions on GraphQL & Relay

    https://kadira.io/blog/graphql/initial-impression-on-relay-and-graphql http://graphql.org/blog/subsc ...

  9. 转 How do GraphQL remote schemas work

    文章转自 prisma 官方博客,写的很不错 In this article, we want to understand how we can use any existing GraphQL AP ...

随机推荐

  1. CentOS7 搭建 Consul 集群

    环境准备: ssh shell工具: 远程连接 三个CentOS示例: 部署集群 配置好各个实例之间的网络访问,以及ssh免密登录. 下载&上传: 1.下载 Consul: Download ...

  2. STL源码剖析——空间配置器Allocator#2 一/二级空间配置器

    上节学习了内存配置后的对象构造行为和内存释放前的对象析构行为,在这一节来学习内存的配置与释放. C++的内存配置基本操作是::operator new(),而释放基本操作是::operator del ...

  3. PAT(B) 1089 狼人杀-简单版(Java)逻辑推理

    题目链接:1089 狼人杀-简单版 (20 point(s)) 题目描述 以下文字摘自<灵机一动·好玩的数学>:"狼人杀"游戏分为狼人.好人两大阵营.在一局" ...

  4. Python开发【第二章】:模块和运算符

    一.模块初识: Python有大量的模块,从而使得开发Python程序非常简洁.类库有包括三中: Python内部提供的模块 业内开源的模块 程序员自己开发的模块 1.Python内部提供一个 sys ...

  5. golang的for循环基本语法

  6. java redisUtils工具类很全

    GitHub地址:https://github.com/whvcse/RedisUtil redisUtils工具类: package com.citydo.utils; import org.spr ...

  7. WPF打印控件内容

    当我们想打印控件内容时,如一个Grid中的内容,可以用WPF中PrintDialog类的PrintVisual()方法来实现 界面如下: XAML代码如下 <Grid> <Grid. ...

  8. net技术方案

    https://www.cnblogs.com/qyq0323/p/11765243.html https://yq.aliyun.com/articles/300527

  9. Spark机器学习基础-特征工程

    对连续值处理 0.binarizer/二值化 from __future__ import print_function from pyspark.sql import SparkSession fr ...

  10. VBA错误处理(十八)

    在(VBScript/VBA)编程中有三种类型的错误: 语法错误 运行时错误 逻辑错误 语法错误 语法错误(也称为解析错误)发生在VBScript的解释时间. 例如,下面一行导致语法错误,因为它缺少一 ...