{"id":13452511,"url":"https://github.com/yarax/swagger-to-graphql","last_synced_at":"2026-01-21T01:34:09.346Z","repository":{"id":39620267,"uuid":"70322562","full_name":"yarax/swagger-to-graphql","owner":"yarax","description":"Swagger to GraphQL API adapter","archived":false,"fork":false,"pushed_at":"2023-03-01T10:46:33.000Z","size":1040,"stargazers_count":924,"open_issues_count":39,"forks_count":150,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-10-31T14:49:28.028Z","etag":null,"topics":["graphql","swagger"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yarax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-08T10:06:22.000Z","updated_at":"2025-10-27T16:35:30.000Z","dependencies_parsed_at":"2024-01-06T03:43:34.006Z","dependency_job_id":"339fd4de-98d9-478e-ace0-0e2e9c021534","html_url":"https://github.com/yarax/swagger-to-graphql","commit_stats":{"total_commits":231,"total_committers":31,"mean_commits":7.451612903225806,"dds":"0.47619047619047616","last_synced_commit":"4796b5e91fb77b2456e77e534869a356515b4b75"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/yarax/swagger-to-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarax%2Fswagger-to-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarax%2Fswagger-to-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarax%2Fswagger-to-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarax%2Fswagger-to-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yarax","download_url":"https://codeload.github.com/yarax/swagger-to-graphql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yarax%2Fswagger-to-graphql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28621748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"ssl_error","status_checked_at":"2026-01-20T23:47:29.996Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","swagger"],"created_at":"2024-07-31T07:01:26.191Z","updated_at":"2026-01-21T01:34:09.319Z","avatar_url":"https://github.com/yarax.png","language":"TypeScript","funding_links":[],"categories":["Tools","TypeScript"],"sub_categories":["Julia Libraries","Tools - Miscellaneous","Crystal Libraries"],"readme":"![Build Status](https://travis-ci.org/yarax/swagger-to-graphql.svg?branch=master)\n\n# Swagger-to-GraphQL\n\nSwagger-to-GraphQL converts your existing Swagger schema to an executable\nGraphQL schema where resolvers perform HTTP calls to certain real endpoints. It\nallows you to move your API to GraphQL with nearly zero effort and maintain both\nREST and GraphQL APIs. Our CLI tool also allows you get the GraphQL schema in\nSchema Definition Language.\n\n[Try it](https://0xr.github.io/swagger-to-graphql-web/) online! You can paste in\nthe url to your own Swagger schema. There are also public OpenAPI schemas\navailable in the [APIs.guru OpenAPI directory](https://apis.guru/browse-apis/).\n\n## Features\n\n- Swagger (OpenAPI 2) and OpenAPI 3 support\n- Bring you own HTTP client\n- Typescript types included\n- Runs in the browser\n- Formdata request body\n- Custom request headers\n\n# Usage\n\n## Basic server\n\nThis library will fetch your swagger schema, convert it to a GraphQL schema and\nconvert GraphQL parameters to REST parameters. From there you are control of\nmaking the actual REST call. This means you can reuse your existing HTTP client,\nuse existing authentication schemes and override any part of the REST call. You\ncan override the REST host, proxy incoming request headers along to your REST\nbackend, add caching etc.\n\n```typescript\nimport express, { Request } from 'express';\nimport graphqlHTTP from 'express-graphql';\nimport { createSchema, CallBackendArguments } from 'swagger-to-graphql';\n\nconst app = express();\n\n// Define your own http client here\nasync function callBackend({\n  context,\n  requestOptions,\n}: CallBackendArguments\u003cRequest\u003e) {\n  return 'Not implemented';\n}\n\ncreateSchema({\n  swaggerSchema: `./petstore.yaml`,\n  callBackend,\n})\n  .then(schema =\u003e {\n    app.use(\n      '/graphql',\n      graphqlHTTP(() =\u003e {\n        return {\n          schema,\n          graphiql: true,\n        };\n      }),\n    );\n\n    app.listen(3009, 'localhost', () =\u003e {\n      console.info('http://localhost:3009/graphql');\n    });\n  })\n  .catch(e =\u003e {\n    console.log(e);\n  });\n```\n\nConstructor (graphQLSchema) arguments:\n\n```typescript\nexport interface Options\u003cTContext\u003e {\n  swaggerSchema: string | JSONSchema;\n  callBackend: (args: CallBackendArguments\u003cTContext\u003e) =\u003e Promise\u003cany\u003e;\n}\n```\n\n- `swaggerUrl` (string) is a path or URL to your swagger schema file. _required_\n- `callBackend` (async function) is called with all parameters needed to make a\n  REST call as well as the GraphQL context.\n\n## CLI usage\n\nYou can use the library just to convert schemas without actually running server\n\n```\nnpx swagger-to-graphql --swagger-schema=/path/to/swagger_schema.json \u003e ./types.graphql\n```\n\n## [Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction/)\n\nApollo federation support can be added by using\n[graphql-transform-federation](https://github.com/0xR/graphql-transform-federation).\nYou can extend your swagger-to-graphql schema with other federated schemas or\nthe other way around. See the\n[demo with a transformed schema](https://github.com/0xR/graphql-transform-federation-blog)\nfor a working example.\n\n## Defining your HTTP client\n\nThis repository has:\n\n- [node-fetch example](./example/node-fetch.ts). Read more about\n  [node-fetch](https://github.com/bitinn/node-fetch).\n- [request-promise example](./example/request-promise.ts). Read more about\n  [request](https://github.com/request/request).\n\nTo get started install `node-fetch` and copy the\n[node-fetch example](./example/node-fetch.ts) into your server.\n\n```sh\nnpm install node-fetch --save\n```\n\n### Implementing your own HTTP client\n\nThere a [unit test](./test/http-adapters-test.ts) for our HTTP client example,\nit might be useful when implementing your own client as well.\n\nThe function `callBackend` is called with 2 parameters:\n\n- `context` is your GraphQL context. For `express-graphql` this is the incoming\n  `request` object by default.\n  [Read more](https://github.com/graphql/express-graphql#options). Use this if\n  you want to proxy headers like `authorization`. For example\n  `const authorizationHeader = context.get('authorization')`.\n- `requestOptions` includes everything you need to make a REST call.\n\n```typescript\nexport interface CallBackendArguments\u003cTContext\u003e {\n  context: TContext;\n  requestOptions: RequestOptions;\n}\n```\n\n### RequestOptions\n\n```typescript\nexport interface RequestOptions {\n  baseUrl?: string;\n  path: string;\n  method: string;\n  headers?: {\n    [key: string]: string;\n  };\n  query?: {\n    [key: string]: string | string[];\n  };\n  body?: any;\n  bodyType: 'json' | 'formData';\n}\n```\n\n- `baseUrl` like defined in your swagger schema: `http://my-backend/v2`\n- `path` the next part of the url: `/widgets`\n- `method` HTTP verb: `get`\n- `headers` HTTP headers which are filled using GraphQL parameters:\n  `{ api_key: 'xxxx-xxxx' }`. Note these are not the http headers sent to the\n  GraphQL server itself. Those will be on the `context` parameter\n- `query` Query parameters for this calls: `{ id: 123 }`. Note this can be an\n  array. You can find some examples on how to deal with arrays in query\n  parameters in the\n  [qs documentation](https://github.com/ljharb/qs#stringifying).\n- `body` the request payload to send with this REST call.\n- `bodyType` how to encode your request payload. When the `bodyType` is\n  `formData` the request should be URL encoded form data. Ensure your HTTP\n  client sends the right `Content-Type` headers.\n\n# Resources\n\n- Blogpost v3:\n  [Start with GraphQL today by converting your Swagger schema](https://xebia.com/blog/start-with-graphql-today-by-converting-your-swagger-schema/)\n- Blogpost:\n  [Moving existing API from REST to GraphQL](https://medium.com/@raxwunter/moving-existing-api-from-rest-to-graphql-205bab22c184)\n- Video:\n  [O.J. Sousa Rodrigues at Vienna.JS](https://www.youtube.com/watch?v=551gKWJEsK0\u0026feature=youtu.be\u0026t=1269\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyarax%2Fswagger-to-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyarax%2Fswagger-to-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyarax%2Fswagger-to-graphql/lists"}