[GraphQL] Reuse GraphQL Selection Sets with Fragments
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的更多相关文章
- [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, ...
- [GraphQL] Reuse Query Fields with GraphQL Fragments
A GraphQL fragment encapsulates a collection of fields that can be included in queries. In this vide ...
- 让ASP.NET Core支持GraphQL之-GraphQL的实现原理
众所周知RESTful API是目前最流行的软件架构风格之一,它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制. RESTful的优越性是毋庸置疑 ...
- [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 ...
- GraphQL ---02 GraphQL和C#结合的实战项目
本文章是介绍和记录如何创建GraphQL项目,以及如何使用GraphQL进行数据的相关操作.项目参照GraphQL .Net 的官方文档进行实践 一.项目结构: 为了更好的和原有的项目结合在一起,尽可 ...
- [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 ...
- graphql 新API 开发方式
我们知道 GraphQL 使用 Schema 来描述数据,并通过制定和实现 GraphQL 规范 定义了支持 Schema 查询的 DSQL (Domain Specific Query Langua ...
- [转] Initial Impressions on GraphQL & Relay
https://kadira.io/blog/graphql/initial-impression-on-relay-and-graphql http://graphql.org/blog/subsc ...
- 转 How do GraphQL remote schemas work
文章转自 prisma 官方博客,写的很不错 In this article, we want to understand how we can use any existing GraphQL AP ...
随机推荐
- 图像处理库 Pillow与PIL
PIL只支持python2的版本到2.7: Python imaging Library : Pillow 是PIL派生的一个分支,支持3以上Python版本. 命令使用pip安装: pip inst ...
- PAT(B) 1083 是否存在相等的差(Java)统计
题目链接:1083 是否存在相等的差 (20 point(s)) 题目描述 给定 N 张卡片,正面分别写上 1.2.--.N,然后全部翻面,洗牌,在背面分别写上 1.2.--.N.将每张牌的正反两面数 ...
- conda命令入坑记
conda命令入坑记 本人使用的软件版本: TypeError: LoadLibrary() argument 1 must be str, not None 网上太多的资料,大多都是在讲path的设 ...
- jwt单点登入
主要有以下三步: 项目一开始我先封装了一个JWTHelper工具包(GitHub下载),主要提供了生成JWT.解析JWT以及校验JWT的方法,其他还有一些加密相关操作.工具包写好后我将打包上传到私 ...
- Vue使用指南(一)
Vue Vue:前台框架 渐进式JavaScript框架 渐进式:vue可以控制页面的一个局部,vue也可以控制整个页面,vue也能控制整个前端项目 -- 根据项目需求,来决定vue控制项目的 ...
- Codeforces Round #419 (Div. 1) (ABCD)
1. 815A Karen and Game 大意: 给定$nm$矩阵, 每次选择一行或一列全部减$1$, 求最少次数使得矩阵全$0$ 贪心, $n>m$时每次取一列, 否则取一行 #inclu ...
- Go 互斥锁(sync.Mutex)和 读写锁(sync.RWMutex)
什么时候需要用到锁? 当程序中就一个线程的时候,是不需要加锁的,但是通常实际的代码不会只是单线程,所以这个时候就需要用到锁了,那么关于锁的使用场景主要涉及到哪些呢? 多个线程在读相同的数据时 多个线程 ...
- ORA-00001:unique constraint violated解决
转自:https://www.2cto.com/database/201211/172340.html ORA-00001:unique constraint violated解决 今天往数据库中插入 ...
- ResourceManager学习之ApplicationMaster,NodeManager管理
ApplicationMaster管理部分主要由三个服务构成,分别是ApplicationMasterLauncher.AMLivelinessMonitor和ApplicationMasterSer ...
- spark 机器学习 knn 代码实现(二)
通过knn 算法规则,计算出s2表中的员工所属的类别原始数据:某公司工资表 s1(训练数据)格式:员工ID,员工类别,工作年限,月薪(K为单位) 101 a类 8年 ...