{"id":13550547,"url":"https://github.com/acro5piano/graphql-rest-proxy","last_synced_at":"2025-04-06T10:09:37.010Z","repository":{"id":34306987,"uuid":"176887410","full_name":"acro5piano/graphql-rest-proxy","owner":"acro5piano","description":"Turn your REST API into GraphQL - A Proxy Server that pipes request from GraphQL to REST with GraphQL DSL, performant nested children, mutations, input types, and more.","archived":false,"fork":false,"pushed_at":"2023-03-01T19:59:02.000Z","size":1565,"stargazers_count":253,"open_issues_count":16,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T09:05:17.553Z","etag":null,"topics":["cli-app","expressjs","graphql","graphql-server","javascript","proxy","rest-api","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/graphql-rest-proxy","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/acro5piano.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":"2019-03-21T06:55:24.000Z","updated_at":"2025-03-24T04:33:39.000Z","dependencies_parsed_at":"2024-01-15T20:51:14.839Z","dependency_job_id":"74c430f6-bdb5-413a-b8ec-522be662f822","html_url":"https://github.com/acro5piano/graphql-rest-proxy","commit_stats":{"total_commits":212,"total_committers":6,"mean_commits":"35.333333333333336","dds":0.5235849056603774,"last_synced_commit":"330e684a1f9ca05777978496d631fcb2154c9f2a"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fgraphql-rest-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fgraphql-rest-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fgraphql-rest-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fgraphql-rest-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acro5piano","download_url":"https://codeload.github.com/acro5piano/graphql-rest-proxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246616864,"owners_count":20806230,"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":["cli-app","expressjs","graphql","graphql-server","javascript","proxy","rest-api","typescript"],"created_at":"2024-08-01T12:01:34.576Z","updated_at":"2025-04-06T10:09:36.983Z","avatar_url":"https://github.com/acro5piano.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"![test](https://github.com/acro5piano/graphql-rest-proxy/workflows/test/badge.svg)\n![release](https://github.com/acro5piano/graphql-rest-proxy/workflows/release/badge.svg)\n[![npm version](https://badge.fury.io/js/graphql-rest-proxy.svg)](https://badge.fury.io/js/graphql-rest-proxy)\n[![codecov](https://codecov.io/gh/acro5piano/graphql-rest-proxy/branch/master/graph/badge.svg)](https://codecov.io/gh/acro5piano/graphql-rest-proxy)\n\n![image](images/logo.png)\n\n# graphql-rest-proxy\n\nConvert your REST server to GraphQL server.\n\n# Install\n\n```sh\nnpm -g install graphql-rest-proxy\n```\n\nOr if you use Yarn:\n\n```sh\nyarn global add graphql-rest-proxy\n```\n\n# Why\n\nWe all know GraphQL is great, so you want to move from REST API to GraphQL.\n\nHowever, it requires a lot of effort to replace your current REST API with a brand new GraphQL server.\n\n`graphql-rest-proxy` comes in to address this issue. It proxies GraphQL to REST API according to the defined schema.\n\n![image](images/how-it-works.png)\n\n# Getting Started\n\n**STEP 1. Define your schema.**\n\n`schema.graphql`\n\n```graphql\ntype User {\n  id: Int\n  name: String\n  isActive: Boolean\n}\n\ntype Query {\n  getUser: User @proxy(get: \"https://my-rest-api.com/user\")\n}\n```\n\n**STEP 2. Run your proxy server.**\n\n```sh\ngraphql-rest-proxy schema.graphql\n\n# =\u003e graphql-rest-proxy is running on http://localhost:5252\n```\n\n**STEP 3. Request!**\n\n```graphql\ncurl -XPOST -H 'Content-Type: application/json' \\\n    -d '{ \"query\": \"{ getUser { id name isActive } }\" }' \\\n    http://localhost:5252/graphql\n```\n\nIt will return like this:\n\n```json\n{\n  \"data\": {\n    \"getUser\": {\n      \"id\": 1,\n      \"name\": \"Tom\",\n      \"isActive\": false\n    }\n  }\n}\n```\n\n# Examples\n\n**Basic Query Proxy**\n\n```graphql\ntype User {\n  id: Int\n  name: String\n}\n\ntype Query {\n  getUser: User @proxy(get: \"https://my-rest-api.com/user\")\n  getUsers: [User] @proxy(get: \"https://my-rest-api.com/users\")\n}\n```\n\n**Query with Parameters**\n\nYou can refer the id of query args by `$id`.\n\n```graphql\ntype User {\n  id: Int\n  name: String\n}\n\ntype Query {\n  getUserById(id: Int!): User @proxy(get: \"https://my-rest-api.com/users/$id\")\n}\n```\n\n**Mutation with Input Parameters**\n\nMutation forward `variables` to the REST API.\n\n```graphql\ninput UserInput {\n  name: String!\n}\n\ntype User {\n  id: Int\n  name: String\n}\n\ntype Mutation {\n  createUser(user: UserInput!): User @proxy(post: \"https://my-rest-api.com/users\")\n  updateUser(id: Int!, user: UserInput!): User @proxy(patch: \"https://my-rest-api.com/users/$id\")\n}\n```\n\nRequest example:\n\n```javascript\nfetch('http://localhost:5252/graphql', {\n  method: 'patch',\n  headers: {\n    'Content-Type': 'application/json',\n  },\n  body: JSON.stringify({\n    query: gql`\n      mutation UpdateUser($id: Int!, $user: UserInput!) {\n        updateUser(id: $id, user: $user) {\n          id\n          name\n        }\n      }\n    `,\n    variables: {\n      id: 1,\n      user: {\n        name: 'acro5piano',\n      },\n    },\n  }),\n})\n```\n\n**Nested Objects**\n\nYou can refer the id of parent object by `$id`.\n\n```graphql\ntype Post {\n  id: Int\n  title: String\n}\n\ntype User {\n  id: Int\n  name: String\n  posts: [Post] @proxy(get: \"https://my-rest-api.com/users/$id/posts\")\n}\n\ntype Query {\n  getUser: User @proxy(get: \"https://my-rest-api.com/user\")\n}\n```\n\n**Specify base url**\n\nYou can set base url to reduce verbosity:\n\n```sh\ngraphql-rest-proxy --baseUrl https://my-rest-api.com schema.graphql\n```\n\n```graphql\ntype Query {\n  getUser: User @proxy(get: \"/user\")\n}\n```\n\n# Configuration\n\nCLI options are:\n\n```\nUsage: graphql-rest-proxy \u003ccommand\u003e [options]\n\nCommands:\n  graphql-rest-proxy \u003cfile\u003e        Start graphql-rest-proxy server.          [default]\n  graphql-rest-proxy print \u003cfile\u003e  Print GraphQL schema\n\nOptions:\n  --version      Show version number                                   [boolean]\n  -c, --config   Specify config file\n  -p, --port     Specify port\n  -b, --baseUrl  Specify proxy base url\n  -h, --help     Show help                                             [boolean]\n```\n\nYou can also set a config file.\n\n`proxy.config.js`\n\n```javascript\nmodule.exports = {\n  baseUrl: 'https://myapi.com',\n  port: 3000,\n}\n```\n\nAnd run with the configuration:\n\n```sh\ngraphql-rest-proxy --config proxy.config.js schema.graphql\n```\n\n# Notes\n\n**Request as less as possible**\n\n`graphql-rest-proxy` does not request if proxy response includes child object. This means you can reduce API call if you includes child object.\n\nFor example, if the schema is like this:\n\n```graphql\ntype Post {\n  id: Int\n  title: String\n}\n\ntype User {\n  id: Int\n  name: String\n  posts: [Post] @proxy(get: \"https://my-rest-api.com/users/$id/posts\")\n}\n\ntype Query {\n  getUser: User @proxy(get: \"https://my-rest-api.com/user\")\n}\n```\n\nAnd REST API returns like this:\n\n```sh\ncurl https://my-rest-api.com/user\n```\n\n```json\n{\n  \"id\": 1,\n  \"name\": \"acro5piano\",\n  \"posts\": {\n    \"id\": 1,\n    \"title\": \"graphql-rest-proxy\"\n  }\n}\n```\n\nIn this case, `posts` is embbed in response, so `graphql-rest-proxy` doesn't request to `https://my-rest-api.com/users/1/posts`.\n\n# Development Status\n\nStill in Beta. If you have any suggestions or feature requests, feel free to open new issues or Pull Requests!\n\nTODO:\n\n- [ ] More type support\n  - [ ] Fragment\n  - [ ] Scalar\n- [ ] Refactoring\n- [ ] Logging\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fgraphql-rest-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facro5piano%2Fgraphql-rest-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fgraphql-rest-proxy/lists"}