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');

http://localhost:8888/graphql

graphiql: true,

query

query{
hello,
}
// OR
{
hello,
}

result

{
"data": {
"hello": "Hello world!"
}
}

refs

https://graphql.org/users/

GraphQL Landscape

https://landscape.graphql.org/category=graph-ql-adopter&format=card-mode&grouping=category&sort=amount

https://h5.ele.me/

https://www.youtube.com/watch?v=g2LbFPAKQZk



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


GraphQL API In Action的更多相关文章

  1. Only one complex type allowed as argument to a web api controller action.

    错误内容: message":"An error has occurred.","exceptionMessage":"Only one c ...

  2. 一个方便查看数据库转换rest/graphql api 的开源软件的github 项目

    https://github.com/dbohdan/automatic-api 是一个不错的github 知识项目,帮助我们 列出了,常见的的数据库可以直接转换为rest/graphql api 的 ...

  3. 通过torodb && hasura graphql 让mongodb 快速支持graphql api

    torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...

  4. 【Graphql实践】使用 Apollo(iOS) 访问 Github 的 Graphql API

    最近在协助调研 Apollo 生成的代码是否有可能跨 Query 共享模型的问题,虽然初步结论是不能,并不是预期的结果,但是在调研过程中积累的一些经验,有必要记录下.如果你也对 Graphql 感兴趣 ...

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

  6. GitHub GraphQL API v4 & GitHub REST API v3

    GitHub, GraphQL API, v4 ,REST API, v3, GraphQL, https://developer.github.com/v4/ https://developer.g ...

  7. GitHub & GraphQL API

    GitHub & GraphQL API https://gist.github.com/xgqfrms/15559e7545f558d85c5efdea79171a3d refs xgqfr ...

  8. 如何让ASP.NET Web API的Action方法在希望的Culture下执行

    在今天编辑推荐的<Hello Web API系列教程--Web API与国际化>一文中,作者通过自定义的HttpMessageHandler的方式根据请求的Accep-Language报头 ...

  9. Android开发-API指南-<action>

    <action> 英文原文:http://developer.android.com/guide/topics/manifest/action-element.html 采集(更新)日期: ...

随机推荐

  1. mysql事务测试

    mysql事务测试 打开mysql的命令行,将自动提交事务给关闭 --查看是否是自动提交 1表示开启,0表示关闭 select @@autocommit; --设置关闭 set autocommit ...

  2. 避免重复提交?分布式服务的幂等性设计! 架构文摘 今天 点击蓝色“架构文摘”关注我哟 加个“星标”,每天上午 09:25,干货推送! 来源:https://www.cnblogs.com/QG-whz/p/10372458.html 作者:melonstreet

    避免重复提交?分布式服务的幂等性设计! 架构文摘  今天 点击蓝色"架构文摘"关注我哟    加个"星标",每天上午 09:25,干货推送!      来源:h ...

  3. Git恢复之前版本的两种方法reset、revert

    实战 回退 1.删除之前的提交 git reset --hard id 推送到远程 git push -f [git log中确实删除了,但是拿到可以恢复] 2.不删除之前的提交 git revert ...

  4. Defining Go Modules

    research!rsc: Go & Versioning https://research.swtch.com/vgo shawn@a:~/gokit/tmp$ go get --helpu ...

  5. csv的读写操作

    cvs简介: CSV 全称 Comma-Separated Values,中文叫逗号分隔值或字符分隔值,它以纯文本形式存储表格数据(数字和文本),其本质就是一个字符序列,可以由任意数目的记录组成,记录 ...

  6. Flutter环境搭建遇坑小结(一)

    对flutter的了解与开发也有一段时间了,总的来说,搭建开发环境遇到的各种坑也是很多,尤其对于初次接触Android开发的人员来说 一.flutter运行提示Running Gradle task ...

  7. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  8. UML——状态图

    状态图(Statechart Diagram),主要用于描述对象在其生命周期中基于事件的动态行为,显示了对象如何根据当前的状态对不同的事件(Events)作出反应(Action).一般我们用状态机来对 ...

  9. Java泛型学习---第二篇

    泛型学习第一篇 1.泛型之擦拭法 泛型是一种类似"模板代码"的技术,不同语言的泛型实现方式不一定相同. Java语言的泛型实现方式是擦拭法(Type Erasure). 所谓擦拭法 ...

  10. 关于RabbitMQ的简单理解

    说明:想要理解RabbitMQ,需要先理解MQ是什么?能做什么?然后根据基础知识去理解RabbitMQ是什么.提供了什么功能. 一.MQ的简单理解 1. 什么是MQ? 消息队列(Message Que ...