On this page, you'll learn in detail about how to query a GraphQL server.

在这个页面,你将会学习更多的关于如何查询GraphQl服务。

Fields

At its simplest, GraphQL is about asking for specific fields on objects. Let's start by looking at a very simple query and the result we get when we run it:

最简单的来说,GraphQl是在Object上请求特定的fields。让我们查看一个非常简单的查询和我们运行它的时候得到的结果:

//查询方法
{
hero {
name
}
}
//运行结果
{
"data": {
"hero": {
"name": "R2-D2"
}
}
}

You can see immediately that the query has exactly the same shape as the result. This is essential to GraphQL, because you always get back what you expect, and the server knows exactly what fields the client is asking for.

我们可以看到查询与结果的形状非常相似。这对于GraphQl是必需的,因为你总是得到你期望的,服务器端完全知道客户端请求的fields.

The field name returns a String type, in this case the name of the main hero of Star Wars,"R2-D2".

name字段返回一个String类型,在这个例子星际战争中主要的英雄的名字:R2-D2

Oh, one more thing - the query above is interactive. That means you can change it as you like and see the new result. Try adding an appearsIn field to the hero object in the query, and see the new result.

此外,上面的查询是交互性的。这也意味着你可以按你自己的意愿去改变他并且得到他的结果。尝试为hero的Object添加一个appearsIn字段,并且查看他的新的结果。

In the previous example, we just asked for the name of our hero which returned a String, but fields can also refer to Objects. In that case, you can make a sub-selection of fields for that object. GraphQL queries can traverse related objects and their fields, letting clients fetch lots of related data in one request, instead of making several roundtrips as one would need in a classic REST architecture.

 在之前的例子中,我们仅仅是查询英雄的名字(返回一个String类型),但是fields同样可以是一个Object.在这个例子中,你可以为这个Object创建一个子部。GraphQl可以便利相关的Object以及他们的fields,假如客户端在一个请求中获取很多相关的数据,而不是像在传统的REST结构中进行好几次往返。
//查询
{
hero {
name
# Queries can have comments!
friends {
name
}
}
}
//结果
{
"data": {
"hero": {
"name": "R2-D2",
"friends": [
{
"name": "Luke Skywalker"
},
{
"name": "Han Solo"
},
{
"name": "Leia Organa"
}
]
}
}
}

Note that in this example, the friends field returns an array of items. GraphQL queries look the same for both single items or lists of items, however we know which one to expect based on what is indicated in the schema.

注意在这个例子中,friends fields返回一个数组。GraphQl查询返回单个或一个集合看起来是相似的,然而,我们知道期望哪个是基于schema定义的。

查询和修改(Queries and Mutations)的更多相关文章

  1. LINQ之路 8: 解释查询(Interpreted Queries)

    LINQ提供了两个平行的架构:针对本地对象集合的本地查询(local queries),以及针对远程数据源的解释查询(Interpreted queries). 在讨论LINQ to SQL等具体技术 ...

  2. InfluxDB学习之InfluxDB连续查询(Continuous Queries)

    在上一篇:InfluxDB学习之InfluxDB数据保留策略(Retention Policies) 中,我们介绍了 InfluxDB的数据保留策略,数据超过保存策略里指定的时间之后,就会被删除. 但 ...

  3. MVC的EF编辑,不用查询直接修改

    EF中会为每个 管理的 实体对象 创建一个代理包装类对象,其中会跟踪 实体对象 的状态和每个属性的状态: 一.通常使用EF更新的方式,先查询出要修改的数据,然后再修改新的值:实体对象被修改的属性 在 ...

  4. SQL练习之不破坏应用程序现有查询的修改模式

    当我还是一个菜鸟的时候,当然现在也是,当我的软件需求发生变化时,并且数据库设计同样要求发生变化,我通常会放弃原有的代码(或者对原有的代码进行大改),先在我知道了两个不破坏应用程序现有查询的修改模式,下 ...

  5. 连续查询(Continuous Queries)

    当数据超过保存策略里指定的时间之后,就会被删除.如果我们不想完全删除掉,比如做一个数据统计采样:把原先每秒的数据,存为每小时的数据,让数据占用的空间大大减少(以降低精度为代价). 这就需要Influx ...

  6. 查询和修改mysql最大连接数的方法

    查询和修改mysql最大连接数的方法切换到mysql库里查询show variables like 'max_connections';show global status like 'Max_use ...

  7. Java对MySQL数据库进行连接、查询和修改(转)

    Java对MySQL数据库进行连接.查询和修改 0. 一般过程: (1) 调用Class.forName()方法加载驱动程序. (2) 调用DriverManager对象的getConnection( ...

  8. MYSQL语句:创建、授权、查询、修改、统计分析等 一 用户的创建、权限设置、删除等

    MYSQL语句:创建.授权.查询.修改.统计分析.. 一.用户的创建.权限设置.删除等 1.首先链接MySQL操作 连接格式:mysql -h 主机地址 -u 用户名 -p 用户密码 (注-u与roo ...

  9. 【层次查询】Hierarchical Queries之亲兄弟间的排序(ORDER SIBLINGS BY)

    http://blog.itpub.net/519536/viewspace-624176 有关层次查询之前的文章参考如下. [层次查询]Hierarchical Queries之"树的遍历 ...

随机推荐

  1. iframe 的使用和登陆退出的实现——整个页面跳转

    iframe中如果只是页面跳转的话,我们依然只是部分的加载的了,为了实现整个页面的所有内容跳转,下面提供了整个页面跳转的方法. iframe例子 1.总的iframe页面(访问就访问这个)  all. ...

  2. python 笔记(一) —— 不要误用 ++i、--i

    ilocker:关注 Android 安全(新手) QQ: 2597294287 在 python 中也可以写 ++i,但含义完全不同于 c/c++.python 的 ++i 并不是将 i 自增 1, ...

  3. javascript刷新父页面的内容

    适应于超级链接和弹出窗口 function RefreshParent() {     if (window.opener != null) {                             ...

  4. 【2016-10-14】【坚持学习】【Day5】【策略模式】

    今天学了策略模式 例子 一个售票系统,针对不同的用户使用不用的计价方式, 环境类:一个业务场景(电影票累,) 抽象类:计价算法 具体实现类:5折算法,满100减20算法,..... 抽象策略类 abs ...

  5. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  6. 单机搭建Android开发环境(二)

    前文介绍了如何优化SSD和内存,以发挥开发主机的最佳性能,同时提到在SSD上创建虚拟机.为什么不装双系统呢?双系统性能应该会更好!采用Windows+虚拟机的方式,主要是考虑到安卓开发和日常办公两方面 ...

  7. 三维网格细分算法(Catmull-Clark subdivision & Loop subdivision)附源码

    下图描述了细分的基本思想,每次细分都是在每条边上插入一个新的顶点,可以看到随着细分次数的增加,折线逐渐变成一条光滑的曲线.曲面细分需要有几何规则和拓扑规则,几何规则用于计算新顶点的位置,拓扑规则用于确 ...

  8. Unity3D FPS帧数修改

    修改Unity的FPS FPS是游戏运行的帧数,本文讲解如何修改Unity引擎的FPS. 步骤 1.在 Edit/Project Settings/Quality  质量设置里把帧数设定关闭,关闭之后 ...

  9. C#小游戏(文字对战游戏)

    第一代,不是很完善,会在后续增加更多的功能 主: using System; using System.Collections.Generic; using System.Linq; using Sy ...

  10. mysql连接数设置操作(Too many connections)

    mysql在使用过程中,发现连接数超了~~~~ [root@linux-node1 ~]# mysql -u glance -h 192.168.1.17 -pEnter password: ERRO ...