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. Avito Cool Challenge 2018 :E. Missing Numbers

    E. Missing Numbers 题目链接:https://codeforces.com/contest/1081/problem/E 题意: 现在有n个数(n为偶数),但只给出a2,a4.... ...

  2. (原创)Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)

    « CloudStack+XenServer详细部署方案(10):高级网络功能应用 (总结)CentOS Linux 5.x在GPT分区不能引导的解决方法 » 2013-1 11 (原创)Linux下 ...

  3. BZOJ 4261: 建设游乐场

    4261: 建设游乐场 Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 38  Solved: 16[Submit][Status][Discuss] ...

  4. Java中UML图

    原文出处:http://blog.sina.com.cn/s/blog_7b3a17130100r95y.html 类(Class) 类(图A)是对象的蓝图,其中包含3个组成部分.第一个是Java中定 ...

  5. python中函数和生成器的运行原理

    #!/usr/bin/env python # -*- coding:utf-8 -*- # author:love_cat # python的函数是如何工作的 # 比方说我们定义了两个函数 def ...

  6. Python学习杂记_14_模块(二)_常用模块

    常用模块 random 模块 import random print(random.random()) # 随机浮点数,默认取0-1,不能指定范围 print(random.randint(1, 20 ...

  7. nagios部署+短信和邮件报警

    操作系统 CentOS6.6  服务端:10.0.0.20 客户端:10.0.0.50 一.nagios的服务端安装部署 1.nagios安装 [root@manager src]# rzrz wai ...

  8. Xamarin for Visual Studio 3.11.590 稳定版 破解补丁 Version 3

    前提概要 全新安装请参考 安装 Xamarin for Visual Studio. Release Log 3.11.590 此版本是紧急修复(HotFix)版,重点改善了 build-tool 及 ...

  9. 前台vue的使用简单小结

    前台vue的使用简单小结 本项目要求:安装有node.js 6.0以及以上安装npm使用vue.js官方安装方法初始化项目npm install安装VueResurce:npm install vue ...

  10. Xamarin XAML语言教程使用Progress属性数据绑定设置进度条进度

    Xamarin XAML语言教程使用Progress属性数据绑定设置进度条进度 开发者除了可以为ProgressBar定义的Progress属性直接赋双精度类型的值外,还可以通过数据绑定的方式为该属性 ...