GraphQL API In Action
GraphQL API In Action
GraphQL API
express
$ yarn add express express-graphql graphql
# OR
$ npm i -S express express-graphql graphql
https://github.com/graphql/express-graphql
https://www.npmjs.com/package/express-graphql
express-graphq
https://graphql.org/graphql-js/express-graphql/
// import graphqlHTTP from 'express-graphql';
// ES6
// const graphqlHTTP = require('express-graphql');
// CommonJS
// default modue
import { graphqlHTTP } from 'express-graphql';
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
// graphqlHTTP
graphqlHTTP({
schema: GraphQLSchema,
graphiql?: ?boolean,
rootValue?: ?any,
context?: ?any,
pretty?: ?boolean,
formatError?: ?Function,
validationRules?: ?Array<any>,
}): Middleware
demos
https://graphql.org/graphql-js/running-an-express-graphql-server/
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-08-0
* @modified
*
* @description
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
*/
const log = console.log;
// server.js
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
const schema = buildSchema(`
type Query {
hello: String
}
`);
// The root provides a resolver function for each API endpoint
const root = {
hello: () => {
return 'Hello world!';
},
};
const app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,// graphiql
}));
app.listen(8888);
console.log('Running a GraphQL API server at http://localhost:8888/graphql');
graphiql: true,
query
query{
hello,
}
// OR
{
hello,
}
result
{
"data": {
"hello": "Hello world!"
}
}

refs
GraphQL Landscape

https://www.youtube.com/watch?v=g2LbFPAKQZk
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
GraphQL API In Action的更多相关文章
- Only one complex type allowed as argument to a web api controller action.
错误内容: message":"An error has occurred.","exceptionMessage":"Only one c ...
- 一个方便查看数据库转换rest/graphql api 的开源软件的github 项目
https://github.com/dbohdan/automatic-api 是一个不错的github 知识项目,帮助我们 列出了,常见的的数据库可以直接转换为rest/graphql api 的 ...
- 通过torodb && hasura graphql 让mongodb 快速支持graphql api
torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...
- 【Graphql实践】使用 Apollo(iOS) 访问 Github 的 Graphql API
最近在协助调研 Apollo 生成的代码是否有可能跨 Query 共享模型的问题,虽然初步结论是不能,并不是预期的结果,但是在调研过程中积累的一些经验,有必要记录下.如果你也对 Graphql 感兴趣 ...
- [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 ...
- GitHub GraphQL API v4 & GitHub REST API v3
GitHub, GraphQL API, v4 ,REST API, v3, GraphQL, https://developer.github.com/v4/ https://developer.g ...
- GitHub & GraphQL API
GitHub & GraphQL API https://gist.github.com/xgqfrms/15559e7545f558d85c5efdea79171a3d refs xgqfr ...
- 如何让ASP.NET Web API的Action方法在希望的Culture下执行
在今天编辑推荐的<Hello Web API系列教程--Web API与国际化>一文中,作者通过自定义的HttpMessageHandler的方式根据请求的Accep-Language报头 ...
- Android开发-API指南-<action>
<action> 英文原文:http://developer.android.com/guide/topics/manifest/action-element.html 采集(更新)日期: ...
随机推荐
- jmeter跳过验证码登录配置:通过手动添加 Cookie 跳过带验证码的登录接口
目录 一.基本配置 二.HTTP请求默认值 三.HTTP信息头管理器 四.HTTP Cookie管理器 五.线程组下接口设置 一.基本配置 二.HTTP请求默认值 (1)jmeter的设置: (2)设 ...
- dotnet .NET
小结: 1.一个.NET应用是一个使用.NET Framework类库来编写,并运行于公共语言运行时Common Language Runtime之上的应用程序. Microsoft .N ...
- setTimeout、Promise、Async/Await 的区别
事件循环中分为宏任务队列和微任务队列其中setTimeout的回调函数放到宏任务队列里,等到执行栈清空以后执行promise.then里的回调函数会放到相应宏任务的微任务队列里,等宏任务里面的同步代码 ...
- P6584 重拳出击
写在前面 来给 zrm 大佬的题写一篇题解. 这题代码实现难度不高,但是比较锻炼思维,而且应该有不少种解法.着实是一道质量很高的题目. 算法思路 首先呢,显然当小 Z 向当前节点的一棵子树走去时,这棵 ...
- 六:SpringBoot-引入JdbcTemplate,和多数据源配置
SpringBoot-引入JdbcTemplate,和多数据源配置 1.JdbcTemplate对象 1.1 JdbcTemplate核心方法 2.SpringBoot中使用JDBCTemplate ...
- 使用Spring StateMachine框架实现状态机
spring statemachine刚出来不久,但是对于一些企业的大型应用的使用还是十分有借鉴意义的. 最近使用了下这个,感觉还是挺好的. 下面举个例子来说下吧: 创建一个Spring Boot的基 ...
- OpenStack (horizon Web管理界面)
horizon 简介 Horizon 为 Openstack 提供一个 WEB 前端的管理界面 (UI 服务 )通过 Horizone 所提供的 DashBoard 服务 , 管理员可以使用通过 WE ...
- java-poi创建模板
package com.jy.demo.web; import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.Cell; i ...
- Apache-三种工作模式(prefork/ worker/Event)
Apache-两种工作模式(prefork/ worker/Event) Apache 2.X 支持插入式并行处理模块,称为多进程处理模块(MPM).在编译apache时必须选择也只能选择一个MPM ...
- Java之jdk环境变量配置
1.jdk下载(按平时下载,注意一下路径就行)2.配置环境变量 :JAVA_HOME.Path.ClassPath3.检查是否成功:(查一下版本,可省略).运行环境(java.javac) 2:电脑- ...