Swagger API to GRAPHQL NPM package trial

Source: Internet
Author: User

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

    • Project structure
├── Dockerfile├── README.md├── api│ └── s.json├── app.js├── docker-compose.yaml├── lib│ ├── index.js│ ├── swagger.js│ ├── typeMap.js│ └── types.js├── package.json└── yarn.lock
    • Code description
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 Mirroring Build
docker-compose build
    • Docker-compose Run
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.