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. 将HDFS中指定文件的内容输出到终端。

    1 import java.io.*; 2 import org.apache.hadoop.conf.Configuration; 3 import org.apache.hadoop.fs.*; ...

  2. css水平、垂直居中的写法

    水平居中 行内元素: text-align: center 块级元素: margin: 0 auto position:absolute +left:50%+ transform:translateX ...

  3. 消息中间件——rocketmq环境配置

    产生原因 RocketMQ概述 RocketMQ 是一款分布式.队列模型的消息中间件,具有以下特点: 能够保证严格的消息顺序 提供丰富的消息拉取模式 高效的订阅者水平扩展能力 实时的消息订阅机制 亿级 ...

  4. 算法总结篇---字典树(Trie)

    目录 写在前面 具体实现 引例: 引例代码: 例题 Phone List Solution: The XOR Largest Pair Solution L语言 Solution: 写在前面 字典树是 ...

  5. java打exe

    参考文章: 注册码: https://www.cnblogs.com/jepson6669/p/9211208.html 官网: https://exe4j.apponic.com/ 在上篇基础上,将 ...

  6. 并发编程(Process对象的join方法)(

    一. Process对象的join方法 在主进程运行过程中如果想并发地执行其他的任务,我们可以开启子进程,此时主进程的任务与子进程的任务分两种情况 情况一:在主进程的任务与子进程的任务彼此独立的情况下 ...

  7. 一篇文章图文并茂地带你轻松学完 JavaScript 继承

    JavaScript 继承 在阅读本文章之前,已经默认你了解了基础的 JavaScript 语法知识,基础的 ES6 语法知识 . 继承种类 简单的继承种类可以分为 构造函数继承 原型链继承 clas ...

  8. 烧录失败导致boot无法加载的解决措施,再也不怕烧成砖了

    目录: 1.usb烧录时出现的问题截图 2.重新擦除boot发现失败的情况 3.解决措施 烧录失败导致boot无法加载的解决措施在烧录系统的时候经常会遇到烧录失败的情况,如果能通过再次执行烧录能烧上肯 ...

  9. 折半搜索(meet in the middle)

    折半搜索(meet in the middle) ​ 我们经常会遇见一些暴力枚举的题目,但是由于时间复杂度太过庞大不得不放弃. ​ 由于子树分支是指数性增长,所以我们考虑将其折半优化; 前言 ​ 这个 ...

  10. java大数函数(附官方文档链接)

    java文档 字段摘要 static BigInteger ONE           BigInteger 的常量 1. static BigInteger TEN           BigInt ...