All Projects → acro5piano → Graphql Rest Proxy

acro5piano / Graphql Rest Proxy

Licence: mit
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.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Graphql Rest Proxy

Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-16.97%)
Mutual labels:  graphql, rest-api, graphql-server
Storefront Api
Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
Stars: ✭ 180 (-17.43%)
Mutual labels:  graphql, rest-api, graphql-server
Fullstack Graphql
🌈 Simple Fullstack GraphQL Application. API built with Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux to access the API. Written in ES6 using Babel + Webpack.
Stars: ✭ 955 (+338.07%)
Mutual labels:  graphql, graphql-server, expressjs
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+8691.28%)
Mutual labels:  graphql, rest-api, graphql-server
Nest Ideas Api
REST API for app ideas built in nestjs
Stars: ✭ 380 (+74.31%)
Mutual labels:  graphql, rest-api, graphql-server
Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-26.61%)
Mutual labels:  graphql, rest-api, graphql-server
Eliasdb
EliasDB a graph-based database.
Stars: ✭ 611 (+180.28%)
Mutual labels:  graphql, rest-api, graphql-server
Graphqldockerproxy
A generic Graphql API for Docker and Kubernetes
Stars: ✭ 38 (-82.57%)
Mutual labels:  graphql, graphql-server, proxy
Fiber
⚡️ Express inspired web framework written in Go
Stars: ✭ 17,334 (+7851.38%)
Mutual labels:  rest-api, expressjs
Gqtx
Code-first type-safe GraphQL Server without codegen or metaprogramming
Stars: ✭ 173 (-20.64%)
Mutual labels:  graphql, graphql-server
Graphql Spqr Spring Boot Starter
Spring Boot 2 starter powered by GraphQL SPQR
Stars: ✭ 187 (-14.22%)
Mutual labels:  graphql, graphql-server
Workshops
Workshops organized to introduce students to security, AI, AR/VR, hardware and software
Stars: ✭ 162 (-25.69%)
Mutual labels:  graphql, rest-api
Express Graphql Typescript Boilerplate
A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
Stars: ✭ 163 (-25.23%)
Mutual labels:  graphql, expressjs
Webtau
Webtau (short for web test automation) is a testing API, command line tool and a framework to write unit, integration and end-to-end tests. Test across REST-API, Graph QL, Browser, Database, CLI and Business Logic with consistent set of matchers and concepts. REPL mode speeds-up tests development. Rich reporting cuts down investigation time.
Stars: ✭ 156 (-28.44%)
Mutual labels:  graphql, rest-api
Gqlify
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (-16.51%)
Mutual labels:  graphql, graphql-server
Autoserver
Create a full-featured REST/GraphQL API from a configuration file
Stars: ✭ 188 (-13.76%)
Mutual labels:  graphql, rest-api
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+1280.28%)
Mutual labels:  graphql, graphql-server
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (-11.01%)
Mutual labels:  graphql, graphql-server
Tipe
🎉 Next Generation API-first CMS for developers. Generate an API-first CMS from a GraphQL schema with offline prototyping and an inline editor
Stars: ✭ 2,157 (+889.45%)
Mutual labels:  graphql, rest-api
Gramps Legacy
The core data source combination engine of GrAMPS.
Stars: ✭ 198 (-9.17%)
Mutual labels:  graphql, graphql-server

test release npm version codecov

image

graphql-rest-proxy

Convert your REST server to GraphQL server.

Install

npm -g install graphql-rest-proxy

Or if you use Yarn:

yarn global add graphql-rest-proxy

Why

We all know GraphQL is great, so you want to move from REST API to GraphQL.

However, it requires a lot of effort to replace your current REST API with a brand new GraphQL server.

graphql-rest-proxy comes in to address this issue. It proxies GraphQL to REST API according to the defined schema.

image

Getting Started

STEP 1. Define your schema.

schema.graphql

type User {
  id: Int
  name: String
  isActive: Boolean
}

type Query {
  getUser: User @proxy(get: "https://my-rest-api.com/user")
}

STEP 2. Run your proxy server.

graphql-rest-proxy schema.graphql

# => graphql-rest-proxy is running on http://localhost:5252

STEP 3. Request!

curl -XPOST -H 'Content-Type: application/json' \
    -d '{ "query": "{ getUser { id name isActive } }" }' \
    http://localhost:5252/graphql

It will return like this:

{
  "data": {
    "getUser": {
      "id": 1,
      "name": "Tom",
      "isActive": false
    }
  }
}

Examples

Basic Query Proxy

type User {
  id: Int
  name: String
}

type Query {
  getUser: User @proxy(get: "https://my-rest-api.com/user")
  getUsers: [User] @proxy(get: "https://my-rest-api.com/users")
}

Query with Parameters

You can refer the id of query args by $id.

type User {
  id: Int
  name: String
}

type Query {
  getUserById(id: Int!): User @proxy(get: "https://my-rest-api.com/users/$id")
}

Mutation with Input Parameters

Mutation forward variables to the REST API.

input UserInput {
  name: String!
}

type User {
  id: Int
  name: String
}

type Mutation {
  createUser(user: UserInput!): User @proxy(post: "https://my-rest-api.com/users")
  updateUser(id: Int!, user: UserInput!): User @proxy(patch: "https://my-rest-api.com/users/$id")
}

Request example:

fetch('http://localhost:5252/graphql', {
  method: 'patch',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    query: gql`
      mutation UpdateUser($id: Int!, $user: UserInput!) {
        updateUser(id: $id, user: $user) {
          id
          name
        }
      }
    `,
    variables: {
      id: 1,
      user: {
        name: 'acro5piano',
      },
    },
  }),
})

Nested Objects

You can refer the id of parent object by $id.

type Post {
  id: Int
  title: String
}

type User {
  id: Int
  name: String
  posts: [Post] @proxy(get: "https://my-rest-api.com/users/$id/posts")
}

type Query {
  getUser: User @proxy(get: "https://my-rest-api.com/user")
}

Specify base url

You can set base url to reduce verbosity:

graphql-rest-proxy --baseUrl https://my-rest-api.com schema.graphql
type Query {
  getUser: User @proxy(get: "/user")
}

Configuration

CLI options are:

Usage: graphql-rest-proxy <command> [options]

Commands:
  graphql-rest-proxy <file>        Start graphql-rest-proxy server.          [default]
  graphql-rest-proxy print <file>  Print GraphQL schema

Options:
  --version      Show version number                                   [boolean]
  -c, --config   Specify config file
  -p, --port     Specify port
  -b, --baseUrl  Specify proxy base url
  -h, --help     Show help                                             [boolean]

You can also set a config file.

proxy.config.js

module.exports = {
  baseUrl: 'https://myapi.com',
  port: 3000,
}

And run with the configuration:

graphql-rest-proxy --config proxy.config.js schema.graphql

Notes

Request as less as possible

graphql-rest-proxy does not request if proxy response includes child object. This means you can reduce API call if you includes child object.

For example, if the schema is like this:

type Post {
  id: Int
  title: String
}

type User {
  id: Int
  name: String
  posts: [Post] @proxy(get: "https://my-rest-api.com/users/$id/posts")
}

type Query {
  getUser: User @proxy(get: "https://my-rest-api.com/user")
}

And REST API returns like this:

curl https://my-rest-api.com/user
{
  "id": 1,
  "name": "acro5piano",
  "posts": {
    "id": 1,
    "title": "graphql-rest-proxy"
  }
}

In this case, posts is embbed in response, so graphql-rest-proxy doesn't request to https://my-rest-api.com/users/1/posts.

Development Status

Still in Beta. If you have any suggestions or feature requests, feel free to open new issues or Pull Requests!

TODO:

  • [ ] More type support
    • [ ] Fragment
    • [ ] Scalar
  • [ ] Refactoring
  • [ ] Logging
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].