We can create the most basic components of our GraphQL Schema using GraphQL's Object Types. These types allow us to group related fields together under a specific type, such as a Video or a User, and then allows us to fetch these types when we query our schema. In this video, we'll learn how to write GraphQL Object Types in GraphQL's Schema language, as well as how to create resolvers for them, and ultimately how to query them.

We are going to refactor this code to make it more readable and meanful:

const { graphql, buildSchema } = require('graphql');

const schema = buildSchema(`
type Query {
id: ID,
title: String,
duration: Int,
watched: Boolean
} type Schema{
query: Query
}
`); const resolvers = {
id : () => '',
title : () => 'bar',
duration : () => ,
watched : true
}; const query = `
query myFirstQuery {
id,
title,
duration,
watched
}
`; graphql(schema, query, resolvers)
.then((result) => console.log(result))
.catch(console.error)

'id', 'title', 'duration', 'watched' are video related. So we create a Video type.

const { graphql, buildSchema } = require('graphql');

const schema = buildSchema(`
type Video {
id: ID,
title: String,
duration: Int,
watched: Boolean
} type Query {
video: Video
} type Schema{
query: Query
}
`); const resolvers = {
video : () => ({
id : '',
title : 'bar',
duration : ,
watched : true
})
}; const query = `
query myFirstQuery {
video {
id,
title,
duration,
watched
}
}
`; graphql(schema, query, resolvers)
.then((result) => console.log(result))
.catch(console.error)

[GraphQL] Use GraphQL's Object Type for Basic Types的更多相关文章

  1. [GraphQL] Create an Input Object Type for Complex Mutations

    When we have certain mutations that require more complex input parameters, we can leverage the Input ...

  2. [GraphQL] Use GraphQL's List Type for Collections

    In order to handle collections of items in a GraphQL Schema, GraphQL has a List Type. In this video, ...

  3. ABAP术语-Object Type

    Object Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/06/1093159.html Description created ...

  4. [terry笔记]IMPDP报错ORA-39083 Object type TYPE failed to create ORA-02304

    今天在使用impdp导入的时候(同一数据库中转换schema),遇到了 ORA-39083: Object type TYPE failed to create with error: ORA-023 ...

  5. java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang.String 转载

    java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang. ...

  6. Object type TYPE failed to create with error

    ORA-39083: Object type TYPE failed to create with error: ORA-02304: invalid object identifier litera ...

  7. impdp报错ORA-39083 ORA-02304 Object type TYPE failed to create

    环境Red Hat Enterprise Linux Server release 5.8 (Tikanga)ORACLE Release 11.2.0.3.0 Production 我用expdp, ...

  8. ABAP术语-Business Object Type

    Business Object Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/10/1033480.html Generic de ...

  9. Property with 'retain (or strong)' attribute must be of object type

    AFNetworking 2.0 当Deployment Target 低于6.0时,AFURLConnectionOperation.h,AFURLSessionManager.h @propert ...

随机推荐

  1. SQL到NOSQL的思维转变

    NOSQL系统一般都会宣传一个特性,那就是性能好,然后为什么呢?关系型数据库发展了这么多年,各种优化工作已经做得很深了,NOSQL系统一般都是吸收关系型数据库的技术,然后,到底是什么因素束缚了关系型数 ...

  2. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  3. RHEL5.8使用yum安装X Window System

    硬件配置:4C+16GB 操作系统:Red Hat Enterprise Linux Server release 5.8 (Tikanga) 服务器中使用的是RHEL5.8操作系统,只安装了基本的功 ...

  4. linux-6的yum软件仓库

    yum命令 命令 作用 yum repolist all  列出所有仓库 yum list all  列出仓库中的所有软件包 yum  info 软件包名称  查看软件包信息 yum install  ...

  5. PHP字符处理基础知识

    <?php class StrDemo { function StrTest() { $s = "abcd"; print '$s length:'.strlen($s).& ...

  6. SQLLDR记录数与文本记录数比较

    我们平时都用sqlldr进行将文本数据加载到数据库,但是有时候由于数据问题导致入库率不能达到100%,因此我们要检测是否存在不能入库的数据记录.以下shell脚本就是统计文本中记录数和数据库中记录数是 ...

  7. C#函数式编程之部分应用

    何谓函数式编程 相信大家在实际的开发中,很多情况下完成一个功能都需要借助多个类,那么我们这里的基本单元就是类.而函数式编程则更加细化,致使我们解决一个功能的基本单元是函数,而不是类,每个功能都是由多个 ...

  8. 讨厌的 StorageFolder.GetFileAsync 异常。

    我们在做WinRT开发的时候,会偶到这样一个场景. 获取一个文件,当他不存在的时候,我们做一些事情. 如果当不存在,我们就创建这么一个文件,那就很好办了. var file = Application ...

  9. addin 笔记

    http://msdn.microsoft.com/en-us/library/vstudio/19dax6cz.aspx VS 加载插件的位置: \My Documents\Visual Studi ...

  10. [Hyper-V]制作一个干净的操作系统模板

    描述: 在Hyper-V里创建虚拟机的时候,我们可以先来创建一个干净的操作系统,将其制作为操作系统模板,该虚拟机的磁盘文件也将被视作基础磁盘以方便基于它创建差异化磁盘 安装其它虚拟机的时候就可以差异化 ...