Code Monkey home page Code Monkey logo

stitching_gateway's Introduction

Stiching API Gateway

A Node JS application that combines two remote GraphQL APIs, one responsible for storing truck data and another for storing planning data.

The FDP data source is a definative list of trucks and includes their name and an indication of fuel burned at different speeds.

The PLAN data source stores data related to project plans that includes a plan name and trucks involved, along with the dates they join and leave a plan (this can happen more than once)

The aim is for the API gateway to provide a single endpoint to these two remote API's and also allow the data to be joined. In the list of trucks participating in a plan the plan stores the truck id. The stiching server needs to use that to fetch the truck name and fuel data.

The two API's are maintained by remote teams and their API's cannot be changed

The FDP API contains data different collections of information related to trucks and uses a structure that is based on a common data type that is extended to expose the type of data required. To get a truck and its fuel data:

query TruckBurnRates {
  dataSources(dataType: Fbr) {
    ... on FBRDataSource {
      fbrTruck(truckId: "a6276400-9e2b-48c7-af57-7b799e83b4c1") {
        uuid
        truckName
        burnRates {
          speed
          mpg
        }
      }
    }
  }
}

To get information about a plan you would use:

{
  getPlanById(id: "b6276400-9e2b-48c7-af57-7b799e83b4c1") {
    id
    name
    trucks {
      id
      truckParticipations {
        joinDate
        leaveDate
      }
    }
  }
}

So one proposed way to get all the data back in a singe query would be to use either:

{
  getPlanById(id: "b6276400-9e2b-48c7-af57-7b799e83b4c1") {
    id
    name
    trucks {
      fbrTruck {
        truckName
        burnRates {
          speed
          mpg
        }
      }
      truckParticipations {
        joinDate
        leaveDate
      }
    }
  }
}

Or, though may cause issues as schemas grows

{
  getPlanById(id: "b6276400-9e2b-48c7-af57-7b799e83b4c1") {
    id
    name
    trucks {
      truckName
      burnRates {
        speed
        mpg
      }
      truckParticipations {
        joinDate
        leaveDate
      }
    }
  }
}

Installation

Tests

There is a small number of tests that can be executed with npm test. These tests demonstrate queries that prove the 2 backend api's and test the required combined query

How do you do it? All the docs on delegateToSchema assume you use a top legel query property and the field to use is at the top level too. How do you work with the need for more complex queries, nested parameters and nested field?

So what is the question?

All the documentation and examples for delegateToSchema describe its use in simple scenarios in which you specify a field in the Query object and a single field in the response. In this case though fetching the data does not follow that, it needs a more specific query and parameters passed own into that, plus the data to pull back is a few layers deep.

  • Is it possible to join these two API's with delegateToSchema?
  • Is there some form of transformation that could make it possible?
  • Is there some form of use of fragments that could help?
  • Does the API gate have to generate the query to use with the little information it has within the stitching resolver?

stitching_gateway's People

Contributors

ztolley avatar yaacovcr avatar dependabot[bot] avatar

Watchers

James Cloos avatar  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.