[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 ...
随机推荐
- (原创)基于FPGA的调光流水灯(Verilog,CPLD/FPGA)
1.Abstract 前几天做了一个呼吸灯,觉得确实挺有意思的:可惜的是只有一个灯管亮,板子上有四个灯,要是能让这些灯有序地亮起来,那应该更有趣味了!跟传统的一样,逻辑上做成一个流水灯的样式, ...
- newLISP 10.5.3 发布,类 Lisp 的脚本语言
newLISP 10.5.3 修复了一些 bug ,为 KMEANS 集群分析器增加了一些函数. newLISP是一个类似Lisp语言的.用于一般用途的脚本语言.它具有 LISP 语言所有的魔力,但更 ...
- Jpeg2000 简介
http://www.baike.com/wiki/Jpeg2000 总结Jpeg2000的六个方面: ⑴ JPEG2000可以方便地实现渐进式传输,这是JPEG2000的重要特征之一.看到这种 ...
- 编写高质量代码改善C#程序的157个建议读书笔记【1-10】
开篇 学生时代,老师常说,好记性不如烂笔头,事实上确实如此,有些知识你在学习的时候确实滚瓜烂熟,但是时间一长又不常用了,可能就生疏了,甚至下次有机会使用到的时候,还需要上网查找资料,所以,还不如常常摘 ...
- 构建单页Web应用
摘自前端农民工的博客 让我们先来看几个网站: coding teambition cloud9 注意这几个网站的相同点,那就是在浏览器中,做了原先“应当”在客户端做的事情.它们的界面切换非常流畅,响应 ...
- 浅谈压缩感知(二十七):压缩感知重构算法之稀疏度自适应匹配追踪(SAMP)
主要内容: SAMP的算法流程 SAMP的MATLAB实现 一维信号的实验与结果 稀疏度K与重构成功概率关系的实验与结果 一.SAMP的算法流程 前面所述大部分OMP及其前改算法都需要已知信号的稀疏度 ...
- Essential C++中文版 前言
天啊,这本书竟是如此轻薄短小.我真想大叫一声“哇欧”!C++ Primer 加上索引.扉页.谢词之后,厚达1237 页,而此书却只有薄薄276 页.套句拳击术语,这是一部“轻量级”作品. 每个人都会好 ...
- 菜鸟日记-HTML
第一部分 HTML---Hyper Text Markup Language--超文本标记语言 1.HTML标准:<html> <head> 网页上的控制信息 <tit ...
- 生成月初月末便于拼接sql
for ($i=1; $i < 13; $i++) { $date = strtotime(date("2015-$i-01")); $firstday = date(&qu ...
- MultiTouch————多点触控,伸缩图片,变换图片位置
前言:当今的手机都支持多点触控功能(可以进行图片伸缩,变换位置),但是我们程序员要怎样结合硬件去实现这个功能呢? 跟随我一起,来学习这个功能 国际惯例:先上DEMO免费下载地址:http://down ...