[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,然后介绍一下这个系列将会使用的示例项目. 关 ...
随机推荐
- 安装python 的 包 paramiko
安装python 的 包 paramiko 安装 依赖 yum -y install gcc python-devel 获取安装 pycryptowget https://pypi.python.or ...
- windows小技巧 从文件夹直接打开命令行位置
windows下从命令行打开某个目录下的东东时,会一直cd ~~~~,更简单的是: 直接用鼠标找到该文件夹或者文件,按住Shift键然后点击鼠标右键,选择"在此处打开命令行"即可 ...
- Linux 所有网卡统计查看小命令
命令使用: [root@localhost home]# -v A1= 'BEGIN{print"---------------------------------------------- ...
- C++混合编程之idlcpp教程Lua篇(2)
在上一篇 C++混合编程之idlcpp教程(一) 中介绍了 idlcpp 工具的使用.现在对 idlcpp 所带的示例教程进行讲解,这里针对的 Lua 语言的例子.首先看第一个示例程序 LuaTuto ...
- C#设计模式——工厂方法
一.为什么需要工厂方法 工厂方法可以这么理解.你规定了一个规范,只要符合这个规范.那么就可以按照你的方式进行操作,这样你就无需知道具体操作的对象是什么,具有什么特性等等,可以进行统一化的操作 ...
- JS学习笔记10_Ajax
1.Ajax概述 Asynchronous JavaScript + XML,支持js与服务器通信.在不unload页面的前提下从服务器获取新数据,以实现更好的用户体验(与传统的单击-等待交互不同的体 ...
- 在.sln文件中设置Visual Studio默认启动项目的简单方法
昨天在一台电脑上用git新签出一个项目进行build,却出现一堆编译错误,而在原先的开发机上build无任何错误.对比分析后发现,开发机上VS的启动项目(startup project)与这台电脑上的 ...
- Nim教程【四】
这是国内第一个关于Nim的系列教程 先说废话 不得不说Rust也是门不错的语言,园子里 有人曾经说: Rust语言除了library或keyword缩写比较恶心以外其他所有地方完爆go 还有人曾这样评 ...
- DDD Example
PART 1: http://www.infoq.com/presentations/model-to-work-evans PART 2: http://www.infoq.com/presenta ...
- 在SecureCRT标签显示IP标题(转)