Swagql

Create a GraphQL schema from swagger spec
Alternatives To Swagql
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Oapi Codegen4,1301,0027 hours ago89August 07, 2023409apache-2.0Go
Generate Go client and server boilerplate from OpenAPI 3 specifications
Openapi Typescript3,562239a day ago90August 14, 202341mitTypeScript
Generate TypeScript types from OpenAPI 3 specs
Drf Yasg3,1652909119 days ago62July 20, 2023242otherPython
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
Graphql Mesh2,9768210 hours ago1,625September 26, 2022187mitTypeScript
GraphQL Mesh — Query anything, run anywhere
Schemathesis1,84643 days ago229August 14, 2023134mitPython
Guarantee flawless API functionality with thorough, high-quality test scenarios generated from your API specification.
Datamodel Code Generator1,8385421 hours ago172August 09, 2023106mitPython
Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
Drf Spectacular1,833533 days ago60July 23, 202364bsd-3-clausePython
Sane and flexible OpenAPI 3 schema generation for Django REST framework.
Compojure Api1,094
2657 months ago135January 16, 201837epl-1.0Clojure
Sweet web apis with Compojure & Swagger
Sofa1,0075115 days ago47September 13, 202350mitTypeScript
The best way to create REST APIs - Generate RESTful APIs from your GraphQL Server
Swagger To Graphql89328610 months ago47October 02, 201935mitTypeScript
Swagger to GraphQL API adapter
Alternatives To Swagql
Select To Compare


Alternative Project Comparisons
Readme

nlm-github nlm-node nlm-version

Build a GraphQL schema from a given Swagger or Open API specification.

Install

To install swagql as devDependency run:

npm i -D swagql

Usage

cat swagger.yml | npx swagql [-p <babel-plugin1-path>,<babel-plugin2-path>] [-n NamePrefix_]> schema.js

Input swagger schema can be in YAML or JSON format. The generated schema exports a schema object and two symbols FETCH and VERIFY_AUTH_STATUS. These symbols should reside in the context used while creating the GraphQL server.

The definition of VERIFY_AUTH_STATUS symbol is optional. It is used to check the authorization status for given request and swagger auth config. If a given request does not satisfy the required auth status, you can throw an auth error from this function. requestContext can be used to hold the information about the current request, such as the request object itself.

In the case where you are merging multiple schemas, you may wish to have all of the methods and types be unique, and can pass the --name-prefix (or -n) flag to prepend the given string to all of the above.

const { schema, FETCH, VERIFY_AUTH_STATUS } = require(pathToSchema);

function verifyAuthStatus(requestContext, authConfig) {
    // verify if current request satisfies authConfig for the given endpoint.
    // if not, throw an auth error.
}
const context = {
  [FETCH]: apiClient.fetch,
  [VERIFY_AUTH_STATUS]: verifyAuthStatus.bind(null, request),
};

Use schema and context in your app

const { graphql } = require('graphql');

graphql(schema, query, context)
  .then(result => console.log(result));

Pagination

If given REST API response includes lists, we need to add page info and edge connection cursors to handle pagination in GraphQL.

To handle this, the generated schema looks for convertArrayToConnection and parseCursorOptions function definitions in ./array-to-connection.js. SwagQL provides a default implementation for array-to-connection. If your APIs return pagination information in the response, the default implementation can be used as follows:

// array-to-connection.js
module.exports = require('swagql/array-to-connection');

If your API responses handle pagination differently, you may have to customize array-to-connection implementation.

Acknowledgements

test/fixtures/petstore.json is taken from https://petstore.swagger.io/v2/swagger.json

Popular Swagger Projects
Popular Schema Projects
Popular Application Programming Interfaces Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Auth
Graphql
Schema
Swagger
Pagination
Openapi
Symbols