graphql-endpoint
A lightweight framework for GraphQL endpoints.
Before (client):
After (client):
// put GraphQL variables into http GET queris // receive GraphQLResult // or make GraphQL like POST without query
Why?
- Reduce your client side request size by moving your GraphQL query from client side to server side.
- Keep your GraphQL queries at server side safely.
- Update your GraphQL queries at server side without publishing new client applications.
Usage
Add graphql-endpoint
to your GraphQL server.
const ApolloServer = const express = const GraphQLEndpoint = const bodyParser = const app = // graphql-endpoint requires json body to be parsedapp// Adopt graphql-endpoint const server = configsserver
Then put your GraphQL query files into src/endpoints/
. For example, the src/endpoints/my_api
with content { example(id: 123) { title, description } }
will serve GraphQL result on /my_api
.
The wrapped API endpoint will support two types of http requests:
- simple http GET: the http GET queries will be collected into GraphQL variables then be sent to GraphQL server with server side predefined GraphQL query.
- http POST: the http POST body be merged with server side predefined query, then be sent to GraphQL server.