# swagger-to-graphql-colinyoung

> 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 effort and maintain both REST and GraphQL APIs.

Latest version **1.6.1** (published 2019-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install swagger-to-graphql-colinyoung
pnpm add swagger-to-graphql-colinyoung
yarn add swagger-to-graphql-colinyoung
bun add swagger-to-graphql-colinyoung
```

Provides the command `swagger-to-graphql-colinyoung`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.1 |
| Published | 2019-06-18 |
| First published | 2019-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 26.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Roman Krivtsov |
| Maintainers | colinyoung |
| Keywords | graphql, swagger |

## Links

- npm: https://www.npmjs.com/package/swagger-to-graphql-colinyoung
- Repository: https://github.com/colinyoung/swagger-to-graphql
- Homepage: https://github.com/colinyoung/swagger-to-graphql#readme
- Issues: https://github.com/colinyoung/swagger-to-graphql/issues
- npm.io page: https://npm.io/package/swagger-to-graphql-colinyoung

## Dependencies (11)

- [yargs](https://npm.io/package/yargs.md) ^8.0.2
- [lodash](https://npm.io/package/lodash.md) ^4.16.4
- [graphql](https://npm.io/package/graphql.md) ^14.1.1
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.8.4
- [request](https://npm.io/package/request.md) ^2.75.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.25.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.1.1
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1
- [graphql-type-json](https://npm.io/package/graphql-type-json.md) ^0.3.0
- [json-schema-ref-parser](https://npm.io/package/json-schema-ref-parser.md) ^3.1.2
- [node-request-by-swagger](https://npm.io/package/node-request-by-swagger.md) ^1.1.3

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.6.1 (latest) — 2019-06-18
- 1.6.0 — 2019-05-03
- 1.5.3 — 2019-05-03
- 1.5.2 — 2019-05-02
- 1.5.1 — 2019-04-25
- 1.5.0 — 2019-04-25
- 1.4.5 — 2019-04-25

## README

# 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 effort and maintain both REST and GraphQL APIs.

<a href="https://medium.com/@raxwunter/moving-existing-api-from-rest-to-graphql-205bab22c184">Why?</a>

*Looking for contributors!*

# Usage

## Basic server

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

const proxyUrl = 'http://petstore.swagger.io/v2';
const pathToSwaggerSchema = './petstore.json';
const customHeaders = {
  // Authorization: 'Basic YWRkOmJhc2ljQXV0aA=='
}

graphQLSchema(pathToSwaggerSchema, proxyUrl, customHeaders).then(schema => {
  app.use('/graphql', graphqlHTTP(() => {
    return {
      schema,
      graphiql: true
    };
  }));

  app.listen(3009, 'localhost', () => {
    console.info('http://localhost:3009/graphql');
  });
}).catch(e => {
  console.log(e);
});
```

Constructor (graphQLSchema) arguments:
* `pathToSwaggerSchema` (string) is a path to your local swagger schema file. *required*
* `proxyUrl` (string) base URL which will be used to hit your HTTP API. Can be taken either from Swagger schema `baseUrl` configuration or from this parameter.
* `customHeaders` (object) key value object of custom headers, which should be included to the HTTP request. Can be used for example for authorization (look at the example above)

## CLI usage

You can use the library just to convert schemas without actually running server

```
npm i -g swagger-to-graphql
# Valid `options` should be added as a comma separated list (case insensitive).
# Current options are listed below.
swagger-to-graphql --swagger=/path/to/swagger_schema.json --options=Opt1,Opt2 > ./types.graphql
```

## CLI options (case insensitive)

- `allow-nan` - instead of Float types that are exclusively just a valid Float or null, use a scalar type `FloatOrNaN` which can be a valid Float, the string value "NaN", or null.
- `empty-to-json` - when a field has no type or is empty, instead of generating an object with a `empty: String` value, return a more flexible JSON type.
- Others TBD

## Video from O.J. Sousa Rodrigues at Vienna.JS
<a href="https://www.youtube.com/watch?v=551gKWJEsK0&feature=youtu.be&t=1269" target="_blank"><img src="https://s3.eu-central-1.amazonaws.com/yarax-public-assets/2019-02-13_13-01-45.png"/></a>


![Build Status](https://travis-ci.org/yarax/swagger-to-graphql.svg?branch=master)

---
_Source: https://npm.io/package/swagger-to-graphql-colinyoung · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
