Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Graphql Rest Proxy | 249 | 1 | 1 | 4 months ago | 23 | November 24, 2022 | 1 | mit | TypeScript | |
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. | ||||||||||
Kubeiql | 113 | 4 years ago | 2 | apache-2.0 | Go | |||||
A GraphQL interface for Kubernetes. | ||||||||||
Dahlia | 92 | 2 | 8 | 3 years ago | 37 | August 01, 2019 | 5 | mit | TypeScript | |
An opinionated React Framework. [Rename to pea.js] | ||||||||||
Apollo Tracing Ruby | 78 | 1 | 4 years ago | 8 | April 24, 2018 | 7 | mit | Ruby | ||
[Maintainers Wanted] Ruby implementation of GraphQL trace data in the Apollo Tracing format | ||||||||||
Graphqldockerproxy | 39 | 3 years ago | 3 | apache-2.0 | TypeScript | |||||
A generic Graphql API for Docker and Kubernetes | ||||||||||
Vertex | 30 | 6 months ago | gpl-3.0 | Go | ||||||
Serverless GraphQL API Gateway | ||||||||||
React Blade | 23 | 1 | 5 years ago | 1 | April 17, 2018 | 2 | JavaScript | |||
Inline GraphQL for the age of Suspense - NO LONGER MAINTAINED | ||||||||||
Pubgrecords Server | 13 | a year ago | gpl-3.0 | JavaScript | ||||||
A GraphQL proxy between the PUBG API and the PubgRecords Apps | ||||||||||
Nuxt.js Craft Boilerplate | 12 | 3 years ago | JavaScript | |||||||
Basic front-end and back-end boilerplate for Nuxt.js together with Craft 3 and Tailwind CSS. | ||||||||||
Nhql | 11 | a year ago | Rust | |||||||
Unofficial GraphQL Reverse Proxy Server for nHentai written in Rust |
Convert your REST server to GraphQL server.
npm -g install graphql-rest-proxy
Or if you use Yarn:
yarn global add graphql-rest-proxy
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.
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
}
}
}
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")
}
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
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
.
Still in Beta. If you have any suggestions or feature requests, feel free to open new issues or Pull Requests!
TODO: