@kbrandwijk/swagger-to-graphql
Swagger2GraphQL converts your existing Swagger schema to GraphQL types where resolvers perform HTTP calls to certain real endpoints. It allows you to move your API to GraphQL with nearly zero afford and maintain both: REST and GraphQL APIs.
Last updated 2 years ago by kbrandwijk .
MIT · Original npm · Tarball · package.json
$ cnpm install @kbrandwijk/swagger-to-graphql 
SYNC missed versions from official npm registry.

Swagger2GraphQL

Swagger2GraphQL converts your existing Swagger schema to GraphQL types where resolvers perform HTTP calls to certain real endpoints. It allows you to move your API to GraphQL with nearly zero afford and maintain both: REST and GraphQL APIs.

Why?

Usage

Basic server

const express = require('express');
const app = express();
const graphqlHTTP = require('express-graphql');
const graphQLSchema = require('swagger-to-graphql');

graphQLSchema('./petstore.json').then(schema => {
  app.use('/graphql', graphqlHTTP(() => {
    return {
      schema,
      context: {
        GQLProxyBaseUrl: API_BASE_URL
      },
      graphiql: true
    };
  }));

  app.listen(3009, 'localhost', () => {
    console.info(`API is here localhost:3009/graphql`);
  });
}).catch(e => {
  throw e;
});

CLI convertion

npm i -g swagger-to-graphql
swagger-to-graphql --swagger=/path/to/swagger_schema.json > ./types.graphql

Authorization

Basic Auth example:

 ...
  context: {
    GQLProxyBaseUrl: API_BASE_URL,
    headers: {
      Authorization: 'Basic YWRkOmJhc2ljQXV0aA==',
      "X-Custom": 'customValue'
    }
    BearerToken: req.get('authorization')
  },
 ...

Bearer Token example:

 ...
  context: {
    GQLProxyBaseUrl: API_BASE_URL,
    headers: {
      Authorization: req.get('authorization'),
      "X-Custom": 'customValue'
    }
  },
 ...

All context options

Current Tags

  • 2.4.3                                ...           latest (2 years ago)

4 Versions

  • 2.4.3                                ...           2 years ago
  • 2.4.2                                ...           2 years ago
  • 1.4.2                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 16
This Month 114
Last Day 12
Last Week 49
Last Month 78
Dependencies (9)

Copyright 2014 - 2016 © taobao.org |