[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,然后介绍一下这个系列将会使用的示例项目. 关 ...
 
随机推荐
- C++中复制构造函数
			
复制构造函数 复制构造函数用于: 根据另一个同类型的对象显示或隐式初始化一个对象 复制一个对象,将它作为实参传给一个函数 从函数返回时复制一个对象 初始化顺序容器中的元素 根据元素初始化式列表初始化数 ...
 - 《理解 ES6》阅读整理:函数(Functions)(一)Default Parameter Values
			
对于任何语言来说,函数都是一个重要的组成部分.在ES6以前,从JavaScript被创建以来,函数一直没有大的改动,留下了一堆的问题和很微妙的行为,导致在JavaScript中使用函数时很容易出现错误 ...
 - PCB检查事项,生成钻孔表
			
PCB检查事项 检查器件是否都放完, 检查连接线是否全部布完, 检查Dangling Line,Via, 查看铜皮是否孤立和无网络铜皮, 检查DRC, 1.选择菜单Display-Status,查看标 ...
 - Jeasyframe 开源框架 稳定版 V1.5 发布
			
这是Jeasyframe开源框架的第一个稳定版本,感谢一起帮忙测试并给予反馈的网友们. 框架官网:http://www.jeasyframe.org/ 产品介绍: Jeasyframe开源框架是基于S ...
 - 学习WPF——了解路由事件
			
入门 我们先来看一个例子 前台代码: 后台代码: 点击按钮的运行效果第一个弹出窗口 第二个弹出窗口: 第三个弹出窗口: 说明 当点击按钮之后,先触发按钮的click事件,再上查找,发现stackpan ...
 - Android中Service深入学习
			
概述 1.当用户在与当前应用程序不同的应用程序时,Service可以继续在后台运行. 2.Service可以让其他组件绑定,以便和它交互并进行进程间通信. 3.Service默认运行在创建它的应用程序 ...
 - RabbitMQ(四) -- Routing
			
RabbitMQ(四) -- Routing `rabbitmq`可以通过路由选择订阅者来发布消息. Bindings 通过下面的函数绑定Exchange与消息队列: channel.queue_bi ...
 - [JS5] 利用onload执行脚本
			
<html> <head> <title>利用onload执行脚本</title> <SCRIPT TYPE="text/JavaScr ...
 - Oracle dmp文件导入(还原)到不同的表空间和不同的用户下
			
------------------------------------- 从生产环境拷贝一个dmp备份文件,在另外一台电脑上搭建测试环境,用imp命令导入dmp文件时提示如下错误: 问题描述: IM ...
 - Java攻城狮面试考题
			
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...