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

@manifoldco/graphql-gen

Package Overview
Dependencies
Maintainers
15
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@manifoldco/graphql-gen

Node client for generating crude GraphQL specs from Swagger OpenAPI. Currently only supports Swagger v2. 💅 Prettifies output via [prettier][prettier].

  • 1.1.0-alpha.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by1200%
Maintainers
15
Weekly downloads
 
Created
Source

⚛️ graphql-gen

Node client for generating crude GraphQL specs from Swagger OpenAPI. Currently only supports Swagger v2. 💅 Prettifies output via prettier.

Support
GraphQL Features
Enum
ID
Implements (allOf)
Non-nullable
Primitives (string, boolean, number)
Query🚫
Mutation🚫

Usage

CLI

npx @manifoldco/graphql-gen api.yaml --output api.graphql

This will save a api.graphql file in the current folder.

Node

npm i --save-dev @manifoldco/graphql-gen prettier
const graphqlGen = require('@manifoldco/swagger-to-graphql');

graphqlGen(spec, [options]);

spec must be in JSON format. For an example of converting YAML to JSON, see the generate.js script.

Options

NameDefaultDescription
output(stdout)Where should the output file be saved?
swagger2Which Swagger version to use. Currently only supports 2.

FAQ

Why does this exist apart from yarax/swagger-to-graphql ?

That didn’t work for our Swagger 2.0 specs 🤷. While normally a PR is the best course of action, this repo exists because it was less effort to build something that works for us than rewrite a popular library (it wasn’t a quick fix).

Why aren’t Queries and Mutations generated from the OpenAPI spec?

While it’s possible to generate something from OpenAPI, it’s intentionally omitted from autogeneration here. Queries and Mutations are best left up to humans, so you can determine what developers should access, and how. Ultimately generating these will always fall short of how real humans could—and should—use your GraphQL endpoint.

Notes

GraphQL is a spec, just like OpenAPI. For this reason, automatic generation isn’t ideal long-term. This library should probably be used as a first-pass to migrate an OpenAPI endpoint to GraphQL. This can generate types, but can’t intelligently generate the best queries and mutations for your specific endpoint.

A common example of this: Swagger has a concept of format: datetime. GraphQL cares about this, but doesn’t assume the formatting. Is this UNIX time? ISO? Are there timezones? Types can be so much more descriptive than mere string or int, and GraphQL gives you the tools to declare this yourself.

FAQs

Package last updated on 29 Jan 2019

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