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. 解决 minicom 不能接收键盘输入问题

    今天突然minicom 不能接受键盘输入了.早上的时候在其他设备上不能识别usb转串口的设备,重新启动电脑后,恢复正常了.下午又出现minicom 不接收键盘输入. 百度了一下解决了. 解决方法 由于 ...

  2. P5858 Golden Swold

    写在前面 简单的单调队列优化 DP 处理略微有点恶心,于是乎,用来取 \(\max\) 的极小值直接开到了 long long 的最小极限,了 define int long long /cy 算法思 ...

  3. flutter--Dart基础语法(一)

    一.前言 Flutter 是 Google 开源的 UI 工具包,帮助开发者通过一套代码库高效构建多平台精美应用,Flutter 开源.免费,拥有宽松的开源协议,支持移动.Web.桌面和嵌入式平台. ...

  4. 客户端,Scala:Spark查询Phoenix

    客户端,Scala:Spark查询Phoenix 1.pom.xml 2.配置文件 2.1config.properties 2.2MyConfig 3.entity实体(与phoenix中的tabl ...

  5. stop脚本

    PID=$(ps -ef | grep eladmin-system-2.0.jar | grep -v grep | awk '{ print $2 }')if [ -z "$PID&qu ...

  6. /etc/fstab和/etc/mtab的区别

    etc/fstab文件的作用         记录了计算机上硬盘分区的相关信息,启动 Linux 的时候,检查分区的 fsck 命令,和挂载分区的 mount 命令,都需要 fstab 中的信息,来正 ...

  7. TCP/IP__TCP/IP协议

    1.定位:指因特网整个TCP/IP协议族,由四个层次组成:网络接入层.网络层.主机到主机层.应用层.也叫DoD模型.每一层都呼叫它的下一层所提供的网络来完成自己的需求. 2.与OSI模型的对应: 3. ...

  8. 让visual studio总是以管理员身份启动

    环境 win10 visual studio 2019 步骤 找到visual studio的安装目录 怎么找? 右击win10开始菜单中visual studio的快捷方式, 依次选择 更多-> ...

  9. SCZ 20170812 T1 HKJ

    因为题面实在是太过暴力,就不贴链接了--我自己重新写一下题面吧-- 题目描述 给定一张带权有向图,设起点为1,终点为n,每个点除编号外还有一个序号,要求输出从起点至终点的最短路经过的点的序号和最短距离 ...

  10. poj3083 Children of the Candy Cor

    Description The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and mus ...