[GraphQL] Use GraphQL's Object Type for Basic Types
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的更多相关文章
- [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 ... 
- [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, ... 
- ABAP术语-Object Type
		Object Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/06/1093159.html Description created ... 
- [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 ... 
- 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. ... 
- Object type TYPE failed to create with error
		ORA-39083: Object type TYPE failed to create with error: ORA-02304: invalid object identifier litera ... 
- 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, ... 
- ABAP术语-Business Object Type
		Business Object Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/10/1033480.html Generic de ... 
- Property with 'retain (or strong)' attribute must be of object type
		AFNetworking 2.0 当Deployment Target 低于6.0时,AFURLConnectionOperation.h,AFURLSessionManager.h @propert ... 
随机推荐
- [Windows-Linux]Windows and Linux 共享文件
			在 windows 上共享一个文件夹 共享操作很简单就不多熬述,不过要注意权限分配问题.我们假定共享了 E:\Develop\Share 这个目录. 我们假设主机局域网的 IP 为 192.168.0 ... 
- Swift 3.0 令人兴奋,但Objective-C也有小改进--Objective-C的类属性
			由于Swift 3.0 出了太多令人兴奋的新特性,人们很容易忽略 Objective-C中的小改动.或许你会觉得苹果提及Objective-C 很可能是为了提高和Swift互操作性(译者注:互操作性主 ... 
- kali linux 渗透测试视频教程  第五课 社会工程学工具集
			第五课 社会工程学工具集 文/玄魂 教程地址:http://edu.51cto.com/course/course_id-1887.html 目录 第五课社会工程学工具集 SET SET的社会工程 ... 
- Kali Linux系列教程之OpenVas安装
			Kali Linux系列教程之OpenVas安装 文 /玄魂 目录 Kali Linux系列教程之OpenVas安装 前言 1. 服务器层组件 2.客户层组件 安装过程 Initial setup ... 
- Spring声明式事务配置与使用
			1.配置: <context:component-scan base-package="com.vrvwh.wh01" /><bean id="data ... 
- Deployment Pipeline using Docker, Jenkins, Java
			Deployment Pipeline using Docker, Jenkins, Java and Couchbase http://blog.couchbase.com/2016/septemb ... 
- thrift之TTransport层的分帧传输类TFramedTransport
			帧传输类就是按照一帧的固定大小来传输数据,所有的写操作首先都是在内存中完成的直到调用了flush操作,然后传输节点在flush操作之后将所有数据根据数据的有效载荷写入数据的长度的二进制块发送出去,允许 ... 
- pro02总结:spring mvc + jdbc
			在pro01的基础上,加入springMVC. applicationContext.xml: <?xml version="1.0" encoding="UTF- ... 
- crossplatform---Nodejs in Visual Studio Code 07.学习Oracle
			1.开始 Node.js:https://nodejs.org OracleDB: https://github.com/oracle/node-oracledb/blob/master/INSTAL ... 
- iOS-网络请求-AFN升级至AFN3.0
			AFNetworking是一款在OS X和iOS下都令人喜爱的网络库.为了迎合iOS新版本的升级, AFNetworking在3.0版本中删除了基于 NSURLConnection API的所有支持. ... 
