[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 ...
随机推荐
- jsf2.0 tomcat 修改页面后无法立马看到页面修改效果
转载于 http://stackoverflow.com/questions/12203657/jsf2-myfaces-xhtml-modifications-do-not-affect-unti ...
- Objective-C入门
厂长最近又有新计划,准备做iOS上的开发,要操作工们(其实就是我自己)学习Objective-C,准备为厂子下一步的发展做出巨大贡献.拿人钱财,替人消灾,又得花时间折腾一门语言.话说自从来到现车间,用 ...
- 团队作业—第二周—SRS
一.系统整体用例图: 二.用户用例图: 三.医院用例图:
- [汇编] C语言中嵌入汇编
>_<" 下面是在C语言中嵌入汇编的例子,下面是三点要注意的~ 1.内联式汇编 2._asm关键字 3.并不是所有中断都能被支持 #include<iostream> ...
- 移动Web与js定时器暂停或不准确计时的问题解决
PC 上的 Firefox.Chrome 和 Safari 等浏览器,都会自动把未激活页面中的 JavaScript 定时器(setTimeout.setInterval)间隔最小值改为 1 秒以上: ...
- [Android] Android Sutdio on Surface Pro 3
Install Android Studio http://www.android-studio.org/index.php/download/androidstudio-download-baidu ...
- 重拾Ajax
本来想专门学习一个Fetch API的相关知识,然后从XMLHttpRequest对象开始看起,看着看着,突然发现自己每天都在使用的ajax竟然还有好多知识点都不熟悉,细思极恐,于是乎从MDN到W3C ...
- Atitit.识别损坏的图像
Atitit.识别损坏的图像 判断jpg图像损坏原理.读取gray line perc ent Png图片送货原理,直接回报EOFException /atiplat_cms/src/com/atti ...
- Leetcode 231 Power of Two 数论
同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...
- ios之如何删除默认的约束
应用场景,你是否尝试过定义一个在设置了autolayout中的xib的控件,然后连线关联了outlet.跟住在代码中设置了针对这个控件的约束,但是发现没有显示效果,控制台里面打印出约束的问题.大概就是 ...