Lets you create a GraphQL gateway service for your
OpenAPI Specifications (OAS)
or Swagger documented API services. This lets you execute
GraphQL queries/mutations against your APIs.
Getting started
CLI
The Command Line Interface (CLI) provides a convenient way to start a GraphQL server wrapping an API for a given OpenAPI Specification:
Install the graphql-4-apis CLI using:
go get -u github.com/chirino/graphql-4-apis
Then, run the OpenAPI-to-GraphQL command and point it to an OpenAPI Specification:
$ graphql-4-apis api myopenapi.json
GraphQL service running at http://localhost:8080/graphql
GraphiQL UI running at http://localhost:8080/graphiql
Characteristics
Queries
Defined headers, query, and path open api parameters become type checked parameters to the GraphQL queries. Responses
get automatically generated graphql types.
Mutations
Non-safe, non-idempotent API operations are translated to GraphQL mutations.
GraphQL Input Objects schemas are generated for the input body so that that input data is type checked.
Authentication
All HTTP headers on the GraphQL request are passed through to the upstream API.
A login mutation is provided so that allows you to store a
bearer token in an http cookie that is used in subsequent request to populate the Authorization header
on API requests. This comes in handy if your using the GraphiQL interface since you can't
easily set Authorization headers using that interface. A logout mutation is also available to
clear the cookie.
API Sanitation
API names not compatible with GraphQL are automatically sanitized. For example, API parameters and data definition names with unsupported
characters (e.g., -, ., ,, :, ;...) are replaced with _.
Swagger and OpenAPI 3 support OpenAPI-to-GraphQL can handle both Swagger (OpenAPI specification 2.0) as well as OpenAPI specification 3.
Support for json objects with dynamic keys GraphQL object types requires all fields of a type to be known, openapi
allows json types with dynamic object keys. In these cases, we map the object type to an array of key value pairs [<ValueType>ResultProp!]
that using this template:
type <ValueType>ResultProp {
key String!
value <ValueType>
}
swagger-to-graphql turns a given Swagger (OpenAPI Specification 2.0) into a GraphQL interface, which resolves against the original API. GraphQL schema is based on endpoints, not on data definitions. No links are considered.
json-to-graphql turns given JSON objects / arrays into a GraphQL schema. resolve functions need to be provided by the user.