[GraphQL] Create a GraphQL Schema

时间:2022-09-22 14:41:16

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. 错误 1 类型“System.Web.Mvc.ModelClientValidationRule”同时存在于“c:\Progra

    问题如图: 解决办法: step1: 首先关闭你应用程序方案,在你保存项目的文件夹下找到ProjectName.csproj  ProjectName是你实际的应用程序名称. step2: 用文字编辑 ...

  2. RCC BUCK变压器设计

    RCC电路工作于临界模式,不是固定工作频率,其设计遵从BUCK原理.Buck电路在最高输入电压时为电感最恶劣工作条件: 以下图为例: 1.首先设定如下参数:输入电压Vin,输出电压Iout,工作频率f ...

  3. 转Class.forName()用法详解

    主要功能 Class.forName(xxx.xx.xx)返回的是一个类 Class.forName(xxx.xx.xx)的作用是要求JVM查找并加载指定的类, 也就是说JVM会执行该类的静态代码段 ...

  4. 【经验】Angularjs 中使用 layDate 日期控件

    layDate 控件地址:http://laydate.layui.com/ 前情:原来系统中使用的日期控件是UI bootstrap(地址:https://angular-ui.github.io/ ...

  5. [改善Java代码]使用valueOf前必须进行校验

    每个枚举都是java.lang.Enum的子类,都可以访问Enum类提供的方法,比如hashCode(),name(),valueOf()等..... 其中valueOf()方法会把一个String类 ...

  6. 输出a-b之间的随机数并考虑异常

    输出a-b之间的随机数并考虑异常 代码如下: package Day05;import java.util.Scanner;import java.util.Random; public class ...

  7. Django—models相关操作

    一.在django后台admin管理页面添加自己增加的表结构 通过终端命令:python3 manage.py makemigrations, python3 manage.py migrate 我们 ...

  8. Mongodb 相关链接

    http://www.cnblogs.com/lanceyan/tag/mongodb/

  9. awk 进阶,百万行文件取交集

    今天我们说的不是简单的交集,而是如下示例: file1: as,er,gf,1212kl,iop,121378,jkl,uio,jki,1214vbnm,yuoi,678i,1215sadfasdf, ...

  10. TensorFlow笔记-06-神经网络优化-损失函数,自定义损失函数,交叉熵

    TensorFlow笔记-06-神经网络优化-损失函数,自定义损失函数,交叉熵 神经元模型:用数学公式比表示为:f(Σi xi*wi + b), f为激活函数 神经网络 是以神经元为基本单位构成的 激 ...