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. 调度 GMP

    小结: 1. 当M从P的本地运行队列获取G时, 如果发现本地队列为空会尝试从其他P盗取一半的G过来,这个机制叫做Work Stealing, 2. Q M一定需要p吗? A 不一定.M正在执行原生代码 ...

  2. Spring Cloud与Eureka

    Spring Cloud与Eureka 一.使用SpringCloud注册中心Eureka 1.1 Eureka和Zookeeper对比 1.1.1 Zookeeper保证CP 1.1.2 Eurek ...

  3. 通过jenkins构建服务,并发布服务,修改Jenkins以Root用户运行

    通过jenkins构建服务,并发布服务,修改Jenkins以Root用户运行 其他博文:从0到1体验Jenkins+Docker+Git+Registry实现CI自动化发布 Jenkins注册中心 一 ...

  4. 使用ganglia 实现监控 hadoop 和 hbase(详细过程总结)

    一,环境准备 hadoop 2.8.2 分布式环境(三个节点 安装请参考 hadoop分布式环境安装) hbase 1.2.6  分布式环境(三个节点 ,安装参考hbase分布式环境安装 ) 主节点采 ...

  5. hive启动错误总结

    1,mysql加载的jar包未找到! ......... Caused by: org.datanucleus.exceptions.NucleusException: Attempt to invo ...

  6. 杂论-FTP

    FTP 一 简单介绍 FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议".用于Internet上的控制文件的双向传输.同时, ...

  7. 高效团队的gitlab flow最佳实践

    当前git是大部分开发团队的首选版本管理工具,一个好的流程规范可以让大家有效地合作,像流水线一样有条不紊地进行团队协作. 业界包含三种flow: Git flow Github flow Gitlab ...

  8. ArrayList源码分析(JDK1.8)

    概述 ArrayList底层是基于数组实现的,并且支持动态扩容的动态数组(变长的集合类).ArrayList允许空值和重复的元素,当向ArrayList中添加元素数量大于其底层数组容量时,会通过扩容机 ...

  9. Flink-v1.12官方网站翻译-P001-Local Installation

    本地安装 按照以下几个步骤下载最新的稳定版本并开始使用. 第一步:下载 为了能够运行Flink,唯一的要求是安装了一个有效的Java 8或11.你可以通过以下命令检查Java的正确安装. java - ...

  10. 图片轮播展示效果-2D实现

    图片的轮播展示效果如果使用2D实现,需要将3D中存在的近大远小效果使用图片的缩放呈现,因此需要存储和计算图片的位置同时还要计算存储图片的缩放信息.将所有图片的位置连线看作是一个椭圆,就可以根据图片的个 ...