IBM / openapi-to-graphql

Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
https://developer.ibm.com/open/projects/openapi-to-graphql/
MIT License
1.6k stars 206 forks source link

Add an option `graphQLSchemaPrefix` to add constants prefix for each generated GraphQL schema #466

Open Justinidlerz opened 2 years ago

Justinidlerz commented 2 years ago

Background:

I use the Apollo Federation to manage a GraphQL gateway. And the histories Restful docs had many many conflict types, Such as Product, Order, Pagination So I want to add a namespace for each transformed API

Changes

In case, when passing the option graphQLSchemaPrefix such as: ModuleA, And the API docs see like:

{
  "/products": {
    "post": {
      "responseBody": {
        "schema": {
          "$ref": "example.json"
        }
      },
      "requestBody": {
        "schema": {
          "type": "object",
          "properties": {
            "item": {
              "name": {
                "type": "String"
              }
            }
          }
        }
      }
    }
  }
}

The generated schema see like:

type ModuleAProduct {
   ...
}

type ModuleAProductInput {
   item: ModuleAItemInput
}

type ModuleAItemInput {
    name: String
}