Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-endpoint

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-endpoint

A lightweight framework for GraphQL endpoints

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

graphql-endpoint

Build Status A lightweight framework for GraphQL endpoints.

Before (client):

fetch('somewhere/graphql', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({ bigGraphQLQueryString, variables })
).then(response => response.json()) // receive GraphQLResult

After (client):

// put GraphQL variables into http GET queris
fetch('somewhere/wrapped/endpoint?variable1=abc&variable2=def')
.then(response => response.json()) // receive GraphQLResult

// or make GraphQL like POST without query
fetch('somehwere/wrapped/endpoint', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({ variables }) // no need query, it's on server side
).then(response => response.json()) // receive GraphQLResult

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 } = require('apollo-server-express')
const express = require('express')
const { GraphQLEndpoint } = require('graphql-endpoint')
const bodyParser = require('body-parser')

const app = express()

// graphql-endpoint requires json body to be parsed
app.use(bodyParser.json())
// Adopt graphql-endpoint
GraphQLEndpoint(app)

const server = new ApolloServer(configs)
server.applyMiddleware({
  app,
  bodyParser: false // optional disable bodyParser, we already have it
})

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.

Keywords

FAQs

Package last updated on 07 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc