All Projects → yarax → Swagger To Graphql

yarax / Swagger To Graphql

Licence: mit
Swagger to GraphQL API adapter

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Swagger To Graphql

Core
The server component of API Platform: hypermedia and GraphQL APIs in minutes
Stars: ✭ 2,004 (+147.1%)
Mutual labels:  graphql, swagger
Openapi To Graphql
Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
Stars: ✭ 973 (+19.98%)
Mutual labels:  graphql, swagger
Netcoreblockly
.NET Core API to Blockly - generate from WebAPI, Swagger, OData, GraphQL =>
Stars: ✭ 121 (-85.08%)
Mutual labels:  graphql, swagger
Templates
.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
Stars: ✭ 2,864 (+253.14%)
Mutual labels:  graphql, swagger
Framework
.NET Core Extensions and Helper NuGet packages.
Stars: ✭ 399 (-50.8%)
Mutual labels:  graphql, swagger
Schemathesis
A modern API testing tool for web applications built with Open API and GraphQL specifications.
Stars: ✭ 768 (-5.3%)
Mutual labels:  graphql, swagger
Eliasdb
EliasDB a graph-based database.
Stars: ✭ 611 (-24.66%)
Mutual labels:  graphql, swagger
Go Gin Api
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用 等等。
Stars: ✭ 730 (-9.99%)
Mutual labels:  graphql, swagger
Kin Openapi
OpenAPI 3.0 implementation for Go (parsing, converting, validation, and more)
Stars: ✭ 776 (-4.32%)
Mutual labels:  swagger
Graphqlgen
⚙️ Generate type-safe resolvers based upon your GraphQL Schema
Stars: ✭ 796 (-1.85%)
Mutual labels:  graphql
Just Api
💥 Test REST, GraphQL APIs
Stars: ✭ 768 (-5.3%)
Mutual labels:  graphql
Graphql Yoga
🧘 Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
Stars: ✭ 6,573 (+710.48%)
Mutual labels:  graphql
Springbootexamples
Spring Boot 学习教程
Stars: ✭ 794 (-2.1%)
Mutual labels:  swagger
Storefront Api Examples
Example custom storefront applications built on Shopify's Storefront API
Stars: ✭ 769 (-5.18%)
Mutual labels:  graphql
Aws Mobile Appsync Sdk Js
JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Stars: ✭ 806 (-0.62%)
Mutual labels:  graphql
Elide
Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
Stars: ✭ 766 (-5.55%)
Mutual labels:  graphql
Optic
Optic documents and tests your API as you build it
Stars: ✭ 760 (-6.29%)
Mutual labels:  swagger
Batch Loader
⚡️ Powerful tool for avoiding N+1 DB or HTTP queries
Stars: ✭ 812 (+0.12%)
Mutual labels:  graphql
Serverless Appsync Plugin
serverless plugin for appsync
Stars: ✭ 804 (-0.86%)
Mutual labels:  graphql
Graphene Sqlalchemy
Graphene SQLAlchemy integration
Stars: ✭ 785 (-3.21%)
Mutual labels:  graphql

Build Status

Swagger-to-GraphQL

Swagger-to-GraphQL converts your existing Swagger schema to an executable GraphQL schema 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. Our CLI tool also allows you get the GraphQL schema in Schema Definition Language.

Try it online! You can paste in the url to your own Swagger schema. There are also public OpenAPI schemas available in the APIs.guru OpenAPI directory.

Features

  • Swagger (OpenAPI 2) and OpenAPI 3 support
  • Bring you own HTTP client
  • Typescript types included
  • Runs in the browser
  • Formdata request body
  • Custom request headers

Usage

Basic server

This library will fetch your swagger schema, convert it to a GraphQL schema and convert GraphQL parameters to REST parameters. From there you are control of making the actual REST call. This means you can reuse your existing HTTP client, use existing authentication schemes and override any part of the REST call. You can override the REST host, proxy incoming request headers along to your REST backend, add caching etc.

import express, { Request } from 'express';
import graphqlHTTP from 'express-graphql';
import { createSchema, CallBackendArguments } from 'swagger-to-graphql';

const app = express();

// Define your own http client here
async function callBackend({
  context,
  requestOptions,
}: CallBackendArguments<Request>) {
  return 'Not implemented';
}

createSchema({
  swaggerSchema: `./petstore.yaml`,
  callBackend,
})
  .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:

export interface Options<TContext> {
  swaggerSchema: string | JSONSchema;
  callBackend: (args: CallBackendArguments<TContext>) => Promise<any>;
}
  • swaggerUrl (string) is a path or URL to your swagger schema file. required
  • callBackend (async function) is called with all parameters needed to make a REST call as well as the GraphQL context.

CLI usage

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

npx swagger-to-graphql --swagger-schema=/path/to/swagger_schema.json > ./types.graphql

Apollo Federation

Apollo federation support can be added by using graphql-transform-federation. You can extend your swagger-to-graphql schema with other federated schemas or the other way around. See the demo with a transformed schema for a working example.

Defining your HTTP client

This repository has:

To get started install node-fetch and copy the node-fetch example into your server.

npm install node-fetch --save

Implementing your own HTTP client

There a unit test for our HTTP client example, it might be useful when implementing your own client as well.

The function callBackend is called with 2 parameters:

  • context is your GraphQL context. For express-graphql this is the incoming request object by default. Read more. Use this if you want to proxy headers like authorization. For example const authorizationHeader = context.get('authorization').
  • requestOptions includes everything you need to make a REST call.
export interface CallBackendArguments<TContext> {
  context: TContext;
  requestOptions: RequestOptions;
}

RequestOptions

export interface RequestOptions {
  baseUrl?: string;
  path: string;
  method: string;
  headers?: {
    [key: string]: string;
  };
  query?: {
    [key: string]: string | string[];
  };
  body?: any;
  bodyType: 'json' | 'formData';
}
  • baseUrl like defined in your swagger schema: http://my-backend/v2
  • path the next part of the url: /widgets
  • method HTTP verb: get
  • headers HTTP headers which are filled using GraphQL parameters: { api_key: 'xxxx-xxxx' }. Note these are not the http headers sent to the GraphQL server itself. Those will be on the context parameter
  • query Query parameters for this calls: { id: 123 }. Note this can be an array. You can find some examples on how to deal with arrays in query parameters in the qs documentation.
  • body the request payload to send with this REST call.
  • bodyType how to encode your request payload. When the bodyType is formData the request should be URL encoded form data. Ensure your HTTP client sends the right Content-Type headers.

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].