[GraphQL] Create a GraphQL Schema
we’ll take a look at the GraphQL Language and write out our first GraphQL Schema. We’ll use the graphql package available to us through npm to parse our graphql language file and resolve our initial query.
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)
We pass in the query we want, GraphQL will verify the query based on the schema we pass in. If it is ok, then will get data from resolver.
[GraphQL] Create a GraphQL Schema的更多相关文章
- [GraphQL] Write a GraphQL Schema in JavaScript
Writing out a GraphQL Schema in the common GraphQL Language can work for simple GraphQL Schemas, but ...
- [GraphQL] Serve a GraphQL Schema as Middleware in Express
If we have a GraphQL Schema expressed in terms of JavaScript, then we have a convenient package avai ...
- [GraphQL] Deploy a GraphQL dev playground with graphql-up
In this lesson we'll use a simple GraphQL IDL schema to deploy and explore a fully functional GraphQ ...
- [GraphQL] Write a GraphQL Mutation
In order to change the data that we can query for in a GraphQL Schema, we have to define what is cal ...
- [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 cli 开发graphql api flow
作用 代码生成 schema 处理 脚手架应用创建 项目管理 安装cli npm install -g graphql-cli 初始化项目(使用.graphqlconfig管理) 以下为demo de ...
- Reusing & Composing GraphQL APIs with GraphQL Bindings
With GraphQL bindings you can embed existing GraphQL APIs into your GraphQL server. In previous blog ...
- [GraphQL] Query a GraphQL API with graphql-request
To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation ...
- 使用Hot Chocolate和.NET 6构建GraphQL应用(1)——GraphQL及示例项目介绍
系列导航 使用Hot Chocolate和.NET 6构建GraphQL应用文章索引 前言 这篇文章是这个系列的第一篇,我们会简单地讨论一下GraphQL,然后介绍一下这个系列将会使用的示例项目. 关 ...
随机推荐
- [原] XAF 如何非常容易禁止清除一个下拉字段的值?
- PHP会话处理相关函数介绍
PHP会话处理相关函数介绍 提交 我的评论 加载中 已评论 PHP会话处理相关函数介绍 2015-03-23 PHP100中文网 PHP100中文网 PHP100中文网 微信号 功能介绍 互联网开发者 ...
- Android的构造器
当Java代码创建一个View实例,或根据XML布局文件加载并构建界面时将需要调用该构造器1.onFinishInflate():这是一个回调方法,当应用从XML布局文件加载该组件并利用它来构建界面之 ...
- Swift 笔记
苹果官方文档 https://developer.apple.com CocoaChina帮助文档 http://www.cocoachina.com/special/swift/ 74个Swift标 ...
- Server Develop (七) Linux 守护进程
守护进程 守护进程,也就是通常说的Daemon进程,是Linux中的后台服务进程.它是一个生存期较长的进程,通常独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件.守护进程常常在系统引导装 ...
- [游戏模版1] MFC最小框架(base function including)
>_<:Here are the template of mini-MFC include: CPen,CBrush,Front,Paint Line and some other gra ...
- jQuery Ztree基本用法
1.首先在页面上有<ul/>标签 <ul id="tree" class="ztree"></ul> 2.定义ztree的配 ...
- CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f834824f\75776659\xxx.dll”--“拒绝访问。 ”
解决方法: 1.找到C:\windows\Temp文件夹 右键属性-->安全选项卡,给IIS_IUSRS帐号赋予权限
- Jetty 9嵌入式开发
官方网址:http://www.eclipse.org/jetty/ 下载地址:http://download.eclipse.org/jetty/stable-9/dist/ 文档网址:http:/ ...
- 安装完grunt和grunt-cli仍然无法识别grunt
如题: 在安装完grunt-cli和grunt之后,仍然不识别grunt. 反复确认是-g安装... 原因: 有可能是nodejs安装出现问题,到时npm的路径没有出现在环境变量里面. 把C:\Use ...