Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kbrandwijk/swagger-to-graphql

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

  • 2.4.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 23 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc