GithubHelp home page GithubHelp logo

graphql-gateway's Introduction

GraphQL Gateway

Background

One of the many reasons engineers love GraphQL is it's ability to query multiple data sources in one request. As engineering teams move away from the traditional "REST" architecture, opportunities for new GraphQL Native applications become possible. As you start building out a distributed system with GraphQL the need for a short develop to deploy cycle becomes crucial. In a microservice architecture with GraphQL, each service owns a GraphQL schema, a slice of the overall system's APIs. The graphql-gateway service uses the concept of schema-delegation to combine multiple GraphQL schemas from different GraphQL servers to create a GraphQL Gateway.

GraphQL Gateways expose a single entry point to query your entire system.

GraphQLGateway

Getting Started

yarn add graphql-binding-gateway

Setup

To create a GraphQL gateway you will need 2 things:

  • A map of GraphQL Bindings
  • typeDefinitions - the collection of type definitions used across your system

Config

You can create a service config with this shape:

type ServiceConfig {
 [serviceName: string]: GraphQLBinding
}

Creating the Gateway

createGateway

  • config - the service config for your gateway
  • server - the server instance (currently supports expressjs)
  • typeDefinitions - the collection of type definitions used across your system and the RootType
  • headersToForward - header keys you would like to forward to services downstream
import express from "express";
import createGateway from "graphql-binding-gateway";
import typeDefinitions from "./typeDefinitions";

const config = {
  Jobs: GraphQLBinding
};

// Create an express server instance
const server = express();

createGateway({
  config,
  typeDefinitions,
  server,
  headersToForward: ["x-user-id"]
});

server.listen(3020, () => {
  console.log(`๐Ÿš€  Server ready.`);
});

You can open the GraphQL playground at http://localhost:3020/graphql

Schema Delegation

When the Gateway receives an incoming HTTP request it parses the request body for a GraphQL query. During the execution phase it delegates or forwards the GraphQL Query document to the GraphQL service that owns it.

GraphQL Bindings are modular building blocks that allow you to embed existing GraphQL APIs into a GraphQL server. This makes it extremely easy to access data from various GraphQL sources and integrate them into a single GraphQL API.

The Gateway uses GraphQL Bindings to create access points to every service in your config.

graphql-gateway's People

Contributors

abhiaiyer91 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.