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的更多相关文章

  1. [GraphQL] Write a GraphQL Schema in JavaScript

    Writing out a GraphQL Schema in the common GraphQL Language can work for simple GraphQL Schemas, but ...

  2. [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 ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. graphql cli 开发graphql api flow

    作用 代码生成 schema 处理 脚手架应用创建 项目管理 安装cli npm install -g graphql-cli 初始化项目(使用.graphqlconfig管理) 以下为demo de ...

  7. Reusing & Composing GraphQL APIs with GraphQL Bindings

    With GraphQL bindings you can embed existing GraphQL APIs into your GraphQL server. In previous blog ...

  8. [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 ...

  9. 使用Hot Chocolate和.NET 6构建GraphQL应用(1)——GraphQL及示例项目介绍

    系列导航 使用Hot Chocolate和.NET 6构建GraphQL应用文章索引 前言 这篇文章是这个系列的第一篇,我们会简单地讨论一下GraphQL,然后介绍一下这个系列将会使用的示例项目. 关 ...

随机推荐

  1. 作死遇到的坑--view向下偏移

    好大一个坑.--谈谈view偏移问题: 先上张图, 图中白色部分.上面的是从网上找的资源.将导航栏隐藏之后用collectionView加上去而实现的滑动标签功能.开始以为是代码中的问题.然后仔细推敲 ...

  2. memcached与.NET的融合使用(二)

    memcached部署完成之后,对当前缓存中数据的监控就显得比较迫切,这里看到网上开源的memadmin比较小巧好用,决定用它来查看监控memcached. 下载memadmin1.0.11,地址:h ...

  3. C#与数据库访问技术总结(十三)之DataReader对象

    DataReader对象与数据获取 DataReader对象以“基于连接”的方式来访问数据库. 也就是说,在访问数据库.执行SQL操作时,DataReader要求一直连在数据库上. 这将会给数据库的连 ...

  4. C#与数据库访问技术总结(九)之实例

    实例 更新记录 在本例子中,建立一个供用户输入学生学号和姓名的文本框和几个对应不同操作类型的更新信息按钮,当用户输入信息以后单击相应的按钮则执行相应的操作.在此实例中还将接触到服务器信息验证的相关知识 ...

  5. paip.导入数据英文音标到数据库mysql为空的问题之道解决原理

    paip.导入数据英文音标到数据库mysql为空的问题之道解决原理 #---原因:mysql 导入工具的bug #---解决:使用双引号不个音标括起来. 作者 老哇的爪子 Attilax 艾龙,  E ...

  6. iOS开发-友盟分享使用(2)

    1.友盟SDK提供功能:分享喜欢的东西到新浪微博.qq空间.为微信朋友圈等等等等社交圈. 2.友盟分享前期准备 (1)注册账号 去官网 (2)创建应用获取appkey 类似5556a53667e*** ...

  7. Android shape 渐变!描边!圆角!示例详解

    看看shape的用法,确实很有帮助.这里我偷懒转一篇比较详细的帖子,和大家一起进步~! Android 中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体 ...

  8. shell切割日志脚本

    #!/bin/bash set -e source /etc/bashrc cd `dirname $` linenum=`wc -l userinfolist.txt | awk '{print $ ...

  9. HDU 1711 Number Sequence (KMP)

    白书说这个是MP,没有对f 数组优化过,所以说KMP有点不准确 #include <stdio.h> int a,b; int T[1000010],P[10010];//从0开始存 in ...

  10. 转:MPlayer源代码分析

    一.Mplayer支持的格式 MPlayer是一个LINUX下的视频播放器,它支持相当多的媒体格式,无论在音频播放还是在视频播放方面,可以说它支持的格式是相当全面的. 视频格式支持:MPEG.AVI. ...