[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,然后介绍一下这个系列将会使用的示例项目. 关 ...
随机推荐
- Rsync 3.1.0 发布,文件同步工具
文件同步工具Rsync 3.1.0发布.2013-09-29 上一个版本还是2011-09-23的3.0.9 过了2年多.Rsync基本是Linux上文件同步的标准了,也可以和inotify配合做实时 ...
- signalR制作微信墙 开源
微信墙 上一篇文章中已经用PHP搭建了一个微信墙获取信息的服务器,我这里使用微软的signalr搭建一个客户端,signalr是一个为开发者开发实时应用的 一个库文件,支持windows server ...
- 大熊君说说JS与设计模式之------命令模式Command
一,总体概要 1,笔者浅谈 日常生活中,我们在看电视的时候,通过遥控器选择我们喜欢的频道时,此时我们就是客户端的角色,遥控器的按钮相当于客户请求,而具体执行的对象就是命令对象, 命令模式把一个请求或者 ...
- 通过git rebase修改commit message
今天发现一个项目的git commit message中的单词拼错了,需要修改一下.但这样简单的修改,需要通过git rebase才能完成. 首先要git rebase到需要修改message的那个c ...
- C++11 并发指南系列
本系列文章主要介绍 C++11 并发编程,计划分为 9 章介绍 C++11 的并发和多线程编程,分别如下: C++11 并发指南一(C++11 多线程初探)(本章计划 1-2 篇,已完成 1 篇) C ...
- [WinAPI] API 14 [获取、设置文件属性和时间]
>_< 为了获取文件属性,用户可以使用GetFileAttributes与GetFileAttributesEx函数. GetFileAttributesEx函数除了返回文件属性外,还返回 ...
- Scala:条件表达式的好处
条件表达式的好处之一是:让代码更简洁,例如在一个需要根据不同条件收集不同值的场景中,多数语言提供的代码如下: ; ) { tmp = xxx; } ) { tmp = yyy; } else { tm ...
- Linux系列笔记 - 用户以及用户组命令
一.前言 这一系列的随笔笔记,并不是详细的说明的命令的原理,只是简单的记录, 以备后期的查看以及复习 二.直接输入命令问题 有时候,我们在用 useradd groupadd等命令时,直接在终端输入的 ...
- atitit. java queue 队列体系and自定义基于数据库的队列总结o7t
atitit. java queue 队列体系and自定义基于数据库的队列总结o7t 1. 阻塞队列和非阻塞队列 1 2. java.util.Queue接口, 1 3. ConcurrentLink ...
- atitit.客户端连接oracle数据库的方式总结
客户端连接oracle数据库的方式总结 目录 Java程序连接一般使用jar驱动连接..... 桌面GUI一般采取c语言驱动oci.dll 直接连接... 间接连接(需要配置tns及其envi var ...