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调优性能监控之show profile

    用show profile查询工具指定具体的type show profile在mysql5.7之后过时 show profile命令用于跟踪执行过的sql语句的资源消耗信息,可以帮助查看sql语句的 ...

  2. vue-cli快速创建项目,可视化创建

    之前学习了交互式创建,发现过程无聊,而且不方便,后面又学习了图形可视化创建,下面进行分享 1.打开cmd 2.输入vue ui,输入后会出现如下 C:\Users\12235>vue ui St ...

  3. Maven 中央仓库

    概述 当你建立一个 Maven 的项目,Maven 会检查你的 pom.xml 文件,以确定哪些依赖下载.首先,Maven 将从本地资源库获得 Maven 的本地资源库依赖资源,如果没有找到,然后把它 ...

  4. 系列trick - bitmask

    目录 系列trick - bitmask 拆位 位运算优化(点少的)图操作 位筛 系列trick - bitmask 拆位 主体思想:位之间不影响,把每一位拆开来考虑贡献,转化成非常容易考虑的 0/1 ...

  5. springmvc框架java.lang.NoSuchMethodException问题解决

    例子:https://blog.csdn.net/huaidandaidai1/article/details/81979704 原因: 在java中,如果一个类A没有自己写构造方法,那么java会自 ...

  6. Uniter 单一框架学习

    unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果. 一.u ...

  7. Docker系列(一)Docker概述,核心概念讲解,安装部署

    部分内容参考链接: Docker实战总结(非常全面,建议收藏) 一. Docker概述 Docker是一个开源的应用容器引擎(基于Go语言开发),让开发者可以打包他们的应用以及依赖包到一个可移植的容器 ...

  8. Spring MVC参数处理

    使用Servlet API作为参数 HttpServletRequest HttpServletResponse HttpSession 使用流作为参数 总结 Spring MVC通过分析处理处理方法 ...

  9. IDEA插件及相关使用技巧

    IDEA插件及相关使用技巧 一.插件 图片背景插件background Image Plus 翻译插件Translation CodeGlance右侧显示代码 Grep Console自定义设置控制台 ...

  10. 6.DHCP配置故障转移(Windows2012)

    准备: 子网对应核心交换机网关配置多个中继 interface Vlan64 ip address 10.10.64.1 255.255.248.0 ip helper-address 10.10.1 ...