OASGraph 转换rest api graphql 试用

创建rest api

lb4 appdemo

参考提示即可

安装 OASGraph

git clone https://github.com/strongloop/oasgraph.git
cd  oasgraph
npm link
或者  npm install -g oasgraph
如果提示权限问题,使用sudo 或者加上 --unsafe-perm
这部分有点慢

启动rest api

cd appdemo 
yarn && yarn start 
默认openapi 地址是:http://127.0.0.1:3000/openapi.json

配置服务

oasgraph http://127.0.0.1:3000/openapi.json

graphql api 访问

http://127.0.0.1:3001/graphql


说明

因为OASGraph 是基于express 以及graphql、openapi 解析运行的,建议的方式是clone 代码,或者使用api 调用
模块调用格式

const express = require('express')
const graphqlHTTP = require('express-graphql')
const OASGraph = require('oasgraph') // use real name here
const app = express()

OASGraph.createGraphQlSchema(oas)
  .then(({schema}) => {
    app.use('/graphql', graphqlHTTP({
      schema,
      graphiql: true
    }))
    app.listen(3001)
  })
  .catch(err => {
    // handle errors when creating the schema
  })

参考资料

https://www.npmjs.com/package/oasgraph
https://github.com/strongloop/oasgraph
http://v4.loopback.io/getting-started-oasgraph.html

posted on   荣锋亮  阅读(509)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2015-10-26 messagepcak 资料

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示