[GraphQL] Reuse Query Fields with GraphQL Fragments
A GraphQL fragment encapsulates a collection of fields that can be included in queries. In this video, we'll look at how to create fragments on types to reduce the amount of typing that needs to occur as queries become more complex. We'll use the GitHub API to test.
We have:
# Type queries into this side of the screen, and you will
# see intelligent typeaheads aware of the current GraphQL type schema,
# live syntax, and validation errors highlighted within the text. # We'll get you started with a simple query showing your username!
query {
organization(login: "moonhighway") {
email,
url,
repository(name: "learning-graphql") {
url,
description
}
},
repository(owner:"facebook" name:"graphql"){
url,
description,
name,
languages(first:1){
nodes {
name
}
}
}
}
To resue 'url', 'description' for Repository, we can create fragment:
fragment CommonFields on Repository {
url,
description
}
Therefore, we can reuse it:
# Type queries into this side of the screen, and you will
# see intelligent typeaheads aware of the current GraphQL type schema,
# live syntax, and validation errors highlighted within the text. # We'll get you started with a simple query showing your username!
query {
organization(login: "moonhighway") {
email,
url,
repository(name: "learning-graphql") {
...CommonFields
}
},
repository(owner:"facebook" name:"graphql"){
...CommonFields
name,
languages(first:1){
nodes {
name
}
}
}
} fragment CommonFields on Repository {
url,
description
}
[GraphQL] Reuse Query Fields with GraphQL Fragments的更多相关文章
- [GraphQL] Reuse GraphQL Selection Sets with Fragments
Fragments are selection sets that can be used across multiple queries. They allow you to refactor re ...
- Graphql介绍(Introduction to GraphQL)
Introduction to GraphQL GraphQL介绍 Learn about GraphQL, how it works, and how to use it in this seri ...
- 使用lua graphql 模块让openresty 支持graphql api
graphql 是一个很不错的api 查询标准语言,已经有一个lua 的版本支持graphql 项目使用docker&&docker-compose 运行 环境准备 模块安装 lu ...
- GraphQL介绍&使用nestjs构建GraphQL查询服务
GraphQL介绍&使用nestjs构建GraphQL查询服务(文章底部附demo地址) GraphQL一种用为你 API 而生的查询语言.出自于Facebook,GraphQL非常易懂,直接 ...
- [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 ...
- [GraphQL] Filter Data Based on Query Arguments with GraphQL
With GraphQL, every field and nested object can have a set of arguments which can be used to request ...
- 通过torodb && hasura graphql 让mongodb 快速支持graphql api
torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...
- 爬取LeetCode题目——如何发送GraphQL Query获取数据
前言 GraphQL 是一种用于 API 的查询语言,是由 Facebook 开源的一种用于提供数据查询服务的抽象框架.在服务端 API 开发中,很多时候定义一个接口返回的数据相对固定,因此要获得 ...
- SpringBoot开发秘籍 - 集成Graphql Query
概述 REST作为一种现代网络应用非常流行的软件架构风格受到广大WEB开发者的喜爱,在目前软件架构设计模式中随处可见REST的身影,但是随着REST的流行与发展,它的一个最大的缺点开始暴露出来: 在很 ...
随机推荐
- 《c程序设计语言》读书笔记-5.3-指针实现strcat
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...
- Extra Judicial Operation
Description The Suitably Protected Programming Contest (SPPC) is a multi-site contest in which conte ...
- Java并发笔记(一)
1. lock (todo) 2. 写时复制容器 CopyOnWrite容器即写时复制的容器.通俗的理解是当我们往一个容器添加元素的时候,不直接往当前容器添加,而是先将当前容器进行Copy,复制出一个 ...
- 斗地主(NOIP2015)
原题传送门 神奇的题目.. 一开始我准备打暴力直接搜答案. 然后发现.. 无限TLE.. 因为O((logN)^14*T)BOOM.. 然后Zxyer告诉可以只DFS顺子...其他的可以一步搞出来.. ...
- Sqlite 教程
http://www.runoob.com/sqlite/sqlite-functions.html
- 华为上机测试题(求亮灯数量-java)
PS:自己写的,自测试OK,供大家参考. /* 一条长廊里依次装有n(1 ≤ n ≤ 65535)盏电灯,从头到尾编号1.2.3.…n-1.n.每盏电灯由一个拉线开关控制.开始,电灯全部关着.有n个学 ...
- Python学习杂记_15_正则表达式
正则表达式 正则表达式就是用来查找字符串的,它能够查找规则比较复杂的字符串.使用正则表达式首先要导入re模块import re s = "besttest is good!besttest ...
- Selenium2+python自动化6-八种元素元素定位(Firebug和firepath)【转载】
前言 自动化只要掌握四步操作:获取元素,操作元素,获取返回结果,断言(返回结果与期望结果是否一致),最后自动出测试报告.本篇主要讲如何用firefox辅助工具进行元素定位.元素定位在这四个环节中是至关 ...
- javascript原型理解一种
http://www.jianshu.com/p/15ac7393bc1f 这个系列值得好好学习的.. // 声明构造函数 function Person(name, age) { this.name ...
- SpringBoot整合Zookeeper和Dubbo
一.Dubbo 1. Dubbo定义 Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来 ...