Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schwer/graphql-to-openapi
Convert a graphql query + graphql schema into an openapi spec.
https://github.com/schwer/graphql-to-openapi
graphql openapi
Last synced: 20 days ago
JSON representation
Convert a graphql query + graphql schema into an openapi spec.
- Host: GitHub
- URL: https://github.com/schwer/graphql-to-openapi
- Owner: schwer
- License: mit
- Created: 2020-01-10T01:07:29.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T18:00:03.000Z (9 months ago)
- Last Synced: 2024-04-14T08:06:32.029Z (9 months ago)
- Topics: graphql, openapi
- Language: TypeScript
- Size: 6.77 MB
- Stars: 79
- Watchers: 4
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# graphql-to-openapi
[![NPM](https://img.shields.io/npm/v/graphql-to-openapi.svg)](https://npmjs.com/graphql-to-openapi)
[![Known Vulnerabilities](https://snyk.io/test/github/schwer/graphql-to-openapi/badge.svg)](https://snyk.io/test/github/schwer/graphql-to-openapi)
[![codecov](https://codecov.io/gh/schwer/graphql-to-openapi/branch/master/graph/badge.svg?token=XTRQ95F57X)](https://codecov.io/gh/schwer/graphql-to-openapi)Convert a graphql query + graphql schema into an openapi spec.
[Demo](https://schwer.github.io/graphql-to-openapi)
Not to be confused with the obviously more useful
[openapi-to-graphql](https://github.com/ibm/openapi-to-graphql).# Usage via CLI
```
npx graphql-to-openapi --yaml --schema --query
```## Unknown Scalar Configuration via the CLI
Unknown scalars are scalar types in the graphql schema that do not obviously map to an openapi type.
The default behavior for unknown scalars is to treat them as `string` types in the output openapi schema.
If you desire to override that behavior, supply a scalar config file to the graphq-to-openapi tool:```
Example CLI usage:npx graphql-to-openapi --scalarConfigFile myScalarConfig.json --yaml --schema --query
---
myScalarConfig.json:
{
"DateTimeScalar": {
"type": "string",
"description": "YYYY-MM-DD date",
"example": "2017-01-01",
"format": "date",
"pattern": "YYYY-MM-DD",
"minLength": 0,
"maxLength": 10
}
}
```# Usage as a module
```typescript
import { graphqlToOpenApi } from 'graphql-to-openapi';const { error, openApiSchema, queryErrors, schemaError } = graphqlToOpenApi({
schema,
query,
});// error will contain any graphql-to-openapi errors if they exist.
// graphql-to-openapi only throws an error if you've failed to name
// the input query. The name of the input query is used to define the
// openapi route name.// schemaError is an error in the parsing of the input schema.
// queryErrors are errors associated with parsing and validating the input query.
// This includes any validation issues when matching the query with the schema.// openApiSchema will contain the deserialized openapi schema for the
// specified query.
```## For Developers contributing to this project
### To get started:
1. Clone the github repo `git clone [email protected]/schwer/graphql-to-openapi`
1. `npm install // install dependencies`
1. `npm run test:watch`### Updating the documentation:
1. The `docs` subdirectory contains a `create-react-app`.
1. `cd docs && npm run start`