[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的流行与发展,它的一个最大的缺点开始暴露出来: 在很 ...
随机推荐
- java中TCP两个例子大写服务器和文件上传
大写服务器的实例: package com.core.net; import java.io.BufferedReader; import java.io.BufferedWriter; import ...
- vs修改快捷键
https://jingyan.baidu.com/album/9158e0006e10d8a254122826.html?picindex=1 https://sanwen8.cn/p/114IrR ...
- bzoj 4897 天赋 有向图的矩阵数定理
4894: 天赋 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 104 Solved: 80[Submit][Status][Discuss] De ...
- java 符号引用与直接引用
简单来说: 符号引用就是字符串,这个字符串包含足够的信息,以供实际使用时可以找到相应的位置.你比如说某个方法的符号引用,如:“java/io/PrintStream.println:(Ljava/la ...
- iframe操作(跨域解决等)
note:当页面内嵌入一个iframe实际上是在dom上新建了一个新的完整的window对象 iframe中取得主窗体 window.top (顶级窗口的window对象) window.parent ...
- react dva routerRedux 备忘
首先你需要import { Link, routerRedux } from 'dva/router'; 在方法里跳转用 function applyJobHandler(){ dispatch(ro ...
- artTemplate 动态加载模版
问题 之前项目中一直有用到artDialog对话框组件,作者后期又发布了js模版引擎,使用过几次,效果感觉还挺好.当自己想把模版放在html之外时,遇到了一点问题. 作者介绍的方式,是在js文件中,通 ...
- mysql创建用户后无法登陆
创建用户后登陆失败的原因是存在匿名用户: root@controller:~# mysql -h localhost -uaa -ppassword ERROR 1045 (28000): Acces ...
- Linux应用层的定时器Timer使用详解【转】
转自:http://blog.csdn.net/wwwtovvv/article/details/8601528 版权声明:本文为博主原创文章,未经博主允许不得转载. linux下定时器的使用 -- ...
- CyanogenMod编译
1. 介绍 本文介绍了i9100手机CyanogenMod 13系统的编译方法 2. 系统要求 笔者使用的环境为CentOS-7-x86_64, 用来为i9100编译CM 13,之所以选择最新版的CM ...