GRAPHQL more convenient API query, operation, Swagger is a convenient open API description standard, currently we have more
Restapi but conversion to GRAPHQL is a cost, fortunately swagger-to-graphql this NPM package helps us simplify the operation
Basic Project
Specific project Reference Https://github.com/rongfengliang/swagger-to-graphql-docker
├── Dockerfile├── README.md├── api│ └── s.json├── app.js├── docker-compose.yaml├── lib│ ├── index.js│ ├── swagger.js│ ├── typeMap.js│ └── types.js├── package.json└── yarn.lock
Package.json Dependency Added {"Name": "SWAGGER-GRAPHQL", "Version": "1.0.0", "main": "Index.js", "License": "MIT", "Dependencie S ": {" Babel-polyfill ":" ^6.26.0 "," 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 RESTAPI ext graphql require (' Babel-polyf Ill '); const EXPRESS = require (' Express '); const APP = Express (); const GRAPHQLHTTP = require (' EXPRESS-GRAPHQL '); const Graphqlschema = require ('./lib '); Type mapping Const PROXYURL = ' https://petstore.swagger.io/v2 '; const PATHTOSWAGGERSCHEMA = ' ${__dirname}/api/s.json '; Swagger API Description Const Customheaders = {Authorization: ' Basic ywrkomjhc2ljqxv0aa== '};graphqlschema (pathtoswaggerschema , Proxyurl, Customheaders). Then (schema = {app.use ('/graphql ', graphqlhttp () = {return {schema, G Raphiql:true}; })); App.listen (3009, ' 0.0.0.0 ', () = {console.info (' http://localhost:3009/graphql '); });}). catch (E = = {Console.log (e);});D Ockerfile Docker image build from Dalongrong/node-yarnworkdir/appcopy. /apprun yarn installexpose 3009ENTRYPOINT ["yarn", "Start"]docker-compose.yaml docker-compose Run File version: "3" services : G:build:./IMAGE:DALONGRONG/SWAGGER-GRAPHQL Ports:-"3,009:3,009"
Run
docker-compose build
docker-compose up -d
- Access
Request Test
Interface documentation
Description
类似的解决方案有 schema stitch graphql-binding
Resources
Https://github.com/yarax/swagger-to-graphql
Https://github.com/graphql-binding/graphql-binding
https://www.prisma.io/blog/reusing-and-composing-graphql-apis-with-graphql-bindings-80a4aa37cff5/
Https://github.com/rongfengliang/swagger-to-graphql-docker
Swagger API to GRAPHQL NPM package trial