{"id":13727349,"url":"https://github.com/graphql-binding/graphql-binding-openapi","last_synced_at":"2025-07-28T07:31:31.226Z","repository":{"id":51774704,"uuid":"118899263","full_name":"graphql-binding/graphql-binding-openapi","owner":"graphql-binding","description":"GraphQL binding implementation for OpenAPI/Swagger endpoints","archived":false,"fork":false,"pushed_at":"2022-12-07T09:17:10.000Z","size":96,"stargazers_count":125,"open_issues_count":4,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-08T04:46:30.459Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/graphql-binding.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}},"created_at":"2018-01-25T10:32:36.000Z","updated_at":"2024-06-02T14:40:51.000Z","dependencies_parsed_at":"2023-01-23T17:15:10.895Z","dependency_job_id":null,"html_url":"https://github.com/graphql-binding/graphql-binding-openapi","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-binding%2Fgraphql-binding-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-binding%2Fgraphql-binding-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-binding%2Fgraphql-binding-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-binding%2Fgraphql-binding-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphql-binding","download_url":"https://codeload.github.com/graphql-binding/graphql-binding-openapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227877896,"owners_count":17833559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-03T01:03:51.197Z","updated_at":"2024-12-03T08:09:11.612Z","avatar_url":"https://github.com/graphql-binding.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# GraphQL Binding for Swagger/OpenAPI\n\n# Deprecation Notices!\n\nIn the last few months, since [the transition of many libraries](https://www.prisma.io/blog/the-guild-takes-over-oss-libraries-vvluy2i4uevs) under [The Guild](http://the-guild.dev)'s leadership, We've reviewed and released many improvements and versions to [graphql-cli](https://github.com/Urigo/graphql-cli), [graphql-config](https://github.com/kamilkisiela/graphql-config) and [graphql-import](https://github.com/ardatan/graphql-import).\n\nWe've reviewed `graphql-binding`, had many meetings with current users and engaged the community also through the [roadmap issue](https://github.com/dotansimha/graphql-binding/issues/325).\n\nWhat we've found is that the new [GraphQL Mesh](https://the-guild.dev/blog/graphql-mesh) library is covering not only all the current capabilities of GraphQL Binding, but also the future ideas that were introduced in the [original GraphQL Binding blog post](https://github.com/prisma-archive/prisma-blog-archive/blob/master/2018-01-12-reusing-and-composing-graphql-apis-with-graphql-bindings.mdx) and haven't come to life yet.\n\nAnd the best thing - [GraphQL Mesh](https://the-guild.dev/blog/graphql-mesh) gives you all those capabilities, even if your source is not a GraphQL service at all!  \nit can be GraphQL, OpenAPI/Swagger, gRPC, SQL or any other source!\nAnd of course you can even merge all those sources into a single SDK.\n\nJust like GraphQL Binding, you get a fully typed SDK (thanks to the protocols SDKs and the [GraphQL Code Generator](https://github.com/dotansimha/graphql-code-generator)), but from any source, and that SDK can run anywhere, as a connector or as a full blown gateway.\nAnd you can share your own \"Mesh Modules\" (which you would probably call \"your own binding\") and our community already created many of those!\nAlso, we decided to simply expose regular GraphQL, so you can choose how to consume it using all the awesome [fluent client SDKs out there](https://hasura.io/blog/fluent-graphql-clients-how-to-write-queries-like-a-boss/).\n\nIf you think that we've missed anything from GraphQL Binding that is not supported in a better way in GraphQL Mesh, please let us know!\n\n\n\n\nEmbed any Swagger/OpenAPI endpoint as GraphQL API into your server application.\n\nBoth yaml and json specifications are supported.\n\n## Install\n\n```sh\nyarn add graphql-binding-openapi\n```\n\n## How it works\n\nA service endpoint that uses the Swagger/OpenAPI specification contains a definition file (in either JSON or YAML format). This definition file has the following structure:\n```json\n{\n    \"swagger\": \"2.0\",\n    \"info\": { },\n    \"host\": \"petstore.swagger.io\",\n    \"basePath\": \"/v2\",\n    \"tags\": [ ],\n    \"schemes\": [ \"http\" ],\n    \"paths\": { },\n    \"securityDefinitions\": {},\n    \"definitions\": { },\n    \"externalDocs\": { }\n}\n```\nAn example for the petstore endpoint can be found [here](./example/petstore.json).\n\nThis endpoint definition is transformed into a GraphQL schema, with all the paths from the endpoint translated into queries and mutations. The query and mutation names are based on the unique `operationName` found in the definition for each path. This schema looks like this:\n```graphql\ntype Query {\n  # GET /pet/findPetsByStatus\n  findPetsByStatus(status: [String]): [findPetsByStatus_items]\n\n  # GET /pet/findPetsByTags\n  findPetsByTags(tags: [String]): [findPetsByTags_items]\n\n  # GET /pet/{petId}\n  getPetById(petId: String): getPetById\n\n  # other queries\n}\n\ntype Mutation {\n  # POST /pet\n  addPet(body: param_addPet_body): addPet\n  \n  # PUT /pet\n  updatePet(body: param_updatePet_body): updatePet\n  \n  # PUT /pet/{petId}\n  updatePetWithForm(petId: String, name: String, status: String): updatePetWithForm\n  \n  # DELETE /pet/{petId}\n  deletePet(api_key: String, petId: String): deletePet\n  \n  # other mutations\n}\n```\nThe full schema for the petstore endpoint can be found [here](./petstore.graphql).\n\nThe remote executable GraphQL schema (containing all the resolvers for querying the original endpoint) is exposed as a binding by `graphql-binding-openapi`, making each query and mutation available as a method on the binding class, for example:\n```js\npetstore.query.findPetsByStatus({ status: \"available\" })\npetstore.mutation.addPet({ /* mutation arguments */ })\n```\n\n## Example\n\n### Standalone\nSee [example directory](example) for a standalone example.\n\n### With `graphql-yoga`\n```js\nconst { OpenApi } = require('graphql-binding-openapi')\nconst { GraphQLServer } = require('graphql-yoga')\n\nconst resolvers = {\n  Query: {\n    findAvailablePets: async (parent, args, context, info) =\u003e {\n      return context.petstore.query.findPetsByStatus({ status: \"available\" }, context, info)\n    }\n  }\n}\n\nconst server = new GraphQLServer({ \n  resolvers, \n  typeDefs,\n  context: async req =\u003e {\n    ...req,\n    petstore: await OpenApi.init('./petstore.json', 'http://petstore.swagger.io/v2')\n  }\n})\n\nserver.start(() =\u003e console.log('Server running on http://localhost:4000'))\n```\n\n## graphql-config support\n\nOpenAPI bindings are supported in `graphql-config` using its extensions model. OpenAPI bindings can be added to the configuration like this:\n```yaml\nprojects:\n  petstore:\n    schemaPath: src/generated/petstore.graphql\n    extensions:\n      openapi:\n        definition: petstore.json\n```\nThis will enable running `graphql get-schema` to output the generated schema from the definition to the defined schemaPath.\n\n## Static bindings\nStatic binding support coming soon.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-binding%2Fgraphql-binding-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphql-binding%2Fgraphql-binding-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-binding%2Fgraphql-binding-openapi/lists"}