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. css垂直居中的几种方式

    1. 对于可以一行处理的 设置 height:apx; line-height:apx; 2.对于一段文字(会多行显示的)            ->2.1如果是可以设置一个固定高度的      ...

  2. linux 安装 pip

    # wget https://bootstrap.pypa.io/get-pip.py # python get-pip.py

  3. UVA 10940 Throwing cards away II

    题意略: 先暴力打表发现规律 N=1 ans=1N=2 ans=2N=3 ans=2N=4 ans=4N=5 ans=2N=6 ans=4N=7 ans=6N=8 ans=8N=9 ans=2N=10 ...

  4. 华为上机测试题(地铁换乘-java)

    PS:自己写的,自测试OK,供大家参考. /* 高级题样题:地铁换乘描述:已知2条地铁线路,其中A为环线,B为东西向线路,线路都是双向的.经过的站点名分别如下,两条线交叉的换乘点用T1.T2表示.编写 ...

  5. Delphi 给结构体指针分配内存,用new(p),释放用dispose(p)

    来自:http://blog.163.com/zhangzhifeng688%40126/blog/static/1652627582010102261748481/ 给结构体指针分配内存  但在很多 ...

  6. sysbench(mysql测试工具 )

    目录 一.基准测试简介 1.什么是基准测试 2.基准测试的作用 3.基准测试的指标 4.基准测试的分类 二.sysbench 1.sysbench简介 2.sysbench安装 3.sysbench语 ...

  7. 【转载】性能监视器(SSAS)

    使用性能监视器,您可以通过性能计数器监视 Microsoft SQL Server Analysis Services (SSAS) 实例的性能. 性能监视器是用于跟踪资源使用情况的 Microsof ...

  8. openstack 监控 - 整合nagios 调研总结

    https://blog.csdn.net/soft_lawrency/article/details/8590562

  9. 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)

    若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...

  10. android okhttp3

    一. 传键值对 public String webLogin() { String responseData = null; OkHttpClient client = new OkHttpClien ...