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的更多相关文章

  1. [GraphQL] Reuse GraphQL Selection Sets with Fragments

    Fragments are selection sets that can be used across multiple queries. They allow you to refactor re ...

  2. Graphql介绍(Introduction to GraphQL)

    Introduction to GraphQL  GraphQL介绍 Learn about GraphQL, how it works, and how to use it in this seri ...

  3. 使用lua graphql 模块让openresty 支持graphql api

      graphql 是一个很不错的api 查询标准语言,已经有一个lua 的版本支持graphql 项目使用docker&&docker-compose 运行 环境准备 模块安装 lu ...

  4. GraphQL介绍&使用nestjs构建GraphQL查询服务

    GraphQL介绍&使用nestjs构建GraphQL查询服务(文章底部附demo地址) GraphQL一种用为你 API 而生的查询语言.出自于Facebook,GraphQL非常易懂,直接 ...

  5. [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 ...

  6. [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 ...

  7. 通过torodb && hasura graphql 让mongodb 快速支持graphql api

    torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...

  8. 爬取LeetCode题目——如何发送GraphQL Query获取数据

    前言   GraphQL 是一种用于 API 的查询语言,是由 Facebook 开源的一种用于提供数据查询服务的抽象框架.在服务端 API 开发中,很多时候定义一个接口返回的数据相对固定,因此要获得 ...

  9. SpringBoot开发秘籍 - 集成Graphql Query

    概述 REST作为一种现代网络应用非常流行的软件架构风格受到广大WEB开发者的喜爱,在目前软件架构设计模式中随处可见REST的身影,但是随着REST的流行与发展,它的一个最大的缺点开始暴露出来: 在很 ...

随机推荐

  1. code forces 994B

    B. Knights of a Polygonal Table time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. python常用20库

    python核心库和统计 简述 1. Requests.最着名的http库由kenneth reitz编写.这是每个python开发人员必备的. 2. Scrapy.如果您参与webscraping, ...

  3. iOSCompile

    https://wiki.videolan.org/iOSCompile iOSCompile Contents [hide] 1 Development environment 2 Get the ...

  4. zlib、libzip、 libzippp 库编译(windows + cmake + vs2013)

    "libzipp" 这库是基于 "libzip" 之上封装的,而 "libzip" 又是基于 "zlib"库封装的,所以 ...

  5. IBM Security AppScan Standard WEB扫描工具

    IBM Security AppScan Standard是一款著名的web漏洞扫描工具, 可以设定登录账户,录制登录 扫描完成后可以生成报告,生成的报告非常详细

  6. zabbix报警邮件qq邮箱收不到的问题

    出现这样问题的根本原因是因为zabbix对中文支持不太友好,乱码导致了邮件无法正常接收. 一.解决zabbix邮件内容为附件 1.安装发送邮件的mailx 以及windows文件转unix文件的命令 ...

  7. 使用bottle进行web开发(1):hello world

    为什么使用bottle?因为简单,就一个py文件,和其他模块没有依赖,3000多行代码. http://www.bottlepy.org/docs/dev/ 既然开始学习,就安装它吧. pip3 in ...

  8. CDH-5.7.0:基于Parcels方式离线安装配置

    http://shiyanjun.cn/archives/1728.html https://www.waitig.com/cdh%E5%AE%89%E8%A3%85.html

  9. Kerberos(转:http://www.cnblogs.com/jankie/archive/2011/08/22/2149285.html)

    Kerberos介绍(全)   微软Windows Server 2003操作系统实现Kerberos 版本5的身份认证协议.Windows Server 2003同时也实现了公钥身份认证的扩展.Ke ...

  10. UVA 1395 Slim Span 最小生成树

    题意: 给你一个图,让你求这个图中所有生成树中满足题目条件的,这个条件是生成树中最长边与最短边的差值最小. 思路: 根据最小瓶颈生成树的定义:在一个有权值的无向图中,求一个生成树最大边的权值尽量小.首 ...