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. 第42讲:Scala中泛型类、泛型函数、泛型在Spark中的广泛应用

    今天来了解下scala的泛型 先让我们看下这段代码 class Triple[F,S,T](val first:F,val second: S,val third: T) val triple = n ...

  2. Mandelbrot和Julia

    概述 mandelbrot julia Mandelbrot 对全体复数z,满足xn+1 =  xn2 + z从x0 = 0起,|x|随n值增加不趋于无穷大,则z属于Mandelbrot集 代码 #i ...

  3. 黑马程序员——for循环的使用与理解

    Console.WriteLine("请输入要打印菱形的行数(不能是偶数)");---------------------- <a href="http://edu ...

  4. Caffe学习系列(20):用训练好的caffemodel来进行分类

    caffe程序自带有一张小猫图片,存放路径为caffe根目录下的 examples/images/cat.jpg, 如果我们想用一个训练好的caffemodel来对这张图片进行分类,那该怎么办呢? 如 ...

  5. ORACLE恢复神器之ODU/AUL/DUL

    分享ORACLE数据库恢复神器之ODU.DUL和AUL工具. ODU:ORACLE DATABASE UNLOADER DUL:DATA UNLOADER AUL:也称MyDUL 关于三种工具说明: ...

  6. 不制作证书是否能加密SQLSERVER与客户端之间传输的数据?

    不制作证书是否能加密SQLSERVER与客户端之间传输的数据? 在做实验之前请先下载network monitor抓包工具 微软官网下载:http://www.microsoft.com/en-us/ ...

  7. 让ASP.NET Web API支持POST纯文本格式(text/plain)的数据

    今天在web api中遇到了这样一个问题,虽然api的参数类型是string,但只能接收post body中json格式的string,不能接收原始string. web api是这样定义的: pub ...

  8. 一页纸商业计划书 (Business Plan) 模板(转载)

    本文转载自:https://blog.eood.cn/business-plan 假如你也有一个 idea ,但是还处于想法阶段,这个商业计划书模板能够帮你理清思路. 这个一页 BP 模板简单实用,分 ...

  9. mongo(五)副本集

    mongo(五)副本集 配置文件 1-3为三个存储节点,其实一个为Primary,两个secondary作为备份,4为仲裁节点 # mongod.conf #where to log logpath= ...

  10. oracle数据库中varchar2陷阱

    oracle数据库相信大家都比较熟悉,数据库中有一种非常常用的数据类型:字符串型. 对应该类型,在oracle中有三种比较常用的类型:varchar2(byte).varchar2(char).nva ...