原理很简单,就是使用swagger api 生成schema 然后代理请求处理api 调用

参考项目 https://github.com/rongfengliang/streamsets-graphql-api

streamsets restapi

使用的npm 包

package.json:

{
"name": "restapi",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"babel-polyfill": "^6.26.0",
"compression": "^1.7.3",
"express": "^4.16.3",
"express-graphql": "^0.6.12",
"graphql": "^0.13.2",
"swagger-to-graphql": "^1.4.0"
},
"scripts": {
"start":"node app"
}
}
app.js
require('babel-polyfill');
const express = require('express');
const app = express();
const graphqlHTTP = require('express-graphql');
const graphQLSchema = require('./lib');
const compression = require('compression');
app.use(compression()); // 修改为对应的server 用户以及地址
const proxyUrl = 'http://admin:admin@localhost:18630/rest';
const pathToSwaggerSchema = `${__dirname}/api/swagger.json`;
// 此处比较重要因为接口是gzip 可以进行内容协商,不使用gzip
const customHeaders = {
"accept-encoding": "identity"
}; graphQLSchema(pathToSwaggerSchema, proxyUrl, customHeaders).then(schema => {
app.use('/graphql', graphqlHTTP(() => {
return {
schema,
graphiql: true
};
})); app.listen(3009, '0.0.0.0', () => {
console.info('http://localhost:3009/graphql');
});
}).catch(e => {
console.log(e);
});

效果


参考资料

https://github.com/rongfengliang/streamsets-graphql-api

 
 
 
 

streamsets rest api 转换 graphql的更多相关文章

  1. harbor rest api 转graphql api

    原理 实际上就是使用graphql 中的binding,首先基于swagger api 进行schema 生成,后边就是 使用binding 进行graphql 请求api 转换为rest api 请 ...

  2. 人人都是 API 设计师:我对 RESTful API、GraphQL、RPC API 的思考

    原文地址:梁桂钊的博客 博客地址:http://blog.720ui.com 欢迎关注公众号:「服务端思维」.一群同频者,一起成长,一起精进,打破认知的局限性. 有一段时间没怎么写文章了,今天提笔写一 ...

  3. swagger api 转graphql npm 包试用

    graphql 比较方便的进行api 的查询,操作,swagger 是一个方便的open api 描述标准,当前我们有比较多的 restapi 但是转换为graphql 是有成本的,还好swagger ...

  4. haproxy 2.0 dataplaneapi rest api 转为graphql docker 镜像

    为了方便直接使用haproxy dataplaneapi graphql 格式的查询,制作了一个简单的docker 镜像 基于dotenv 进行配置管理,可以直接通过环境变量传入参数,处理不同hapr ...

  5. haproxy 2.0 dataplaneapi rest api 转为graphql

    haproxy 2.0 dataplaneapi rest api 是比较全的,以下是一个简单的集成graphql,通过swagger-to-graphql 转换为graphql api 方便使用 环 ...

  6. Delphi 编码转换 Unicode gbk big5(使用LCMapString设置区域后,再用API转换)

    原文:http://blog.dream4dev.com/article.asp?id=17 function UnicodeEncode(Str: string; CodePage: integer ...

  7. 如何使用 window api 转换字符集?

    //宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...

  8. 如何使用 window api 转换字符集?(std::string与std::wstring的相互转换)

    //宽字符转多字节 std::string W2A(const std::wstring& utf8) { int buffSize = WideCharToMultiByte(CP_ACP, ...

  9. normalizr api 转换类库使用

    1. 项目初始化 yarn init yarn add normalizr 项目结构 app.js package.json user.json 2. 使用 a. app.js const userj ...

随机推荐

  1. android--------阿里 Sophix移动热修复

    移动热修复(Mobile Hotfix)是阿里云提供的全平台App热修复服务方案.产品基于阿里巴巴首创hotpatch技术,提供最细粒度热修复能力,让您无需等待实时修复应用线上问题. 移动热修复提供的 ...

  2. PHP函数总结 (七)

    <?php /** * 匿名函数(闭包函数): * php>=5.3 * 允许临时创建一个没有指定名称的函数,常作为回调函数参数的值 * * 闭包的另一个概念: * 在内部函数中可以使用外 ...

  3. 『cs231n』线性分类器损失函数

    代码部分 SVM损失函数 & SoftMax损失函数: 注意一下softmax损失的用法: SVM损失函数: import numpy as np def L_i(x, y, W): ''' ...

  4. OA项目(MVC项目)

    1. 新建,项目,其他项目类型,空白解决方案 2. 选中解决方案,添加,新建项目,类库: (1)添加OA.Model,删除其中的Class1.cs (2)添加OA.DAL(数据访问层),删除Class ...

  5. forget words out1

    forget word 1● information 2● infomation 3● mation 4● pavilion 5● river 6● mouth 7● fish 8● lick 9● ...

  6. jquery条形码生成器

    <!DOCTYPE html><html> <head>        <meta charset="UTF-8">         ...

  7. Visual Studio build tools 安装出错的一种解决办法

    一般是安装包丢失或损坏,那么我么可以用离线下载的方式来先行下载. 用 -h 看下帮助 主要是Layout参数. 下载完,到下载目录安装吧.

  8. python执行系统命令后获取返回值

    import os, subprocess # os.system('dir') #执行系统命令,没有获取返回值,windows下中文乱码 # result = os.popen('dir') #执行 ...

  9. eclipse中使用Maven新建Servlet2.5的Web项目

    前言 我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的 ...

  10. 在ant中将依赖jar包一并打包的方法

    一般jar包里面是不包含jar文件的,如果自己的类有依赖其他jar包,可以通过ant命令将这些jar包解析,然后和自己的class文件打在一起,命令如下: build.xml 1 2 3 4 5 6 ...