博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[GraphQL] Reuse Query Fields with GraphQL Fragments
阅读量:5070 次
发布时间:2019-06-12

本文共 1613 字,大约阅读时间需要 5 分钟。

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  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}

 

转载于:https://www.cnblogs.com/Answer1215/p/10261423.html

你可能感兴趣的文章
Scrapy实战篇(三)之爬取豆瓣电影短评
查看>>
HDU 5510 Bazinga KMP
查看>>
[13年迁移]Firefox下margin-top问题
查看>>
Zookeeper常用命令 (转)
查看>>
【CF888E】Maximum Subsequence 折半搜索
查看>>
Java程序IP v6与IP v4的设置
查看>>
RUP(Rational Unified Process),统一软件开发过程
查看>>
eclipse下的tomcat内存设置大小
查看>>
数据库链路创建方法
查看>>
linux文件
查看>>
Linux CentOS6.5上搭建环境遇到的问题
查看>>
Enterprise Library - Data Access Application Block 6.0.1304
查看>>
重构代码 —— 函数即变量(Replace temp with Query)
查看>>
vmware tools 的安装(Read-only file system 的解决)
查看>>
Bootstrap栅格学习
查看>>
程序员的数学
查看>>
聚合与组合
查看>>
数据库图片存储也读取
查看>>
jQuery如何获得select选中的值?input单选radio选中的值
查看>>
粘贴板工具,剪切板工具
查看>>