Giter VIP home page Giter VIP logo

graphql-build-time-stitching's Introduction

Stitching of GraphQL schemas at build time

The purpose of this project is to stitch together different GraphQL schemas obtained via introspection from remote services, and then run a gateway server that loads the stitched schema and resolves incoming GraphQL queries by delegating them to the corresponding remote services.

The remote services could any type of source, but in this example only a GraphQL service and an OpenAPI service are used as examples.

Usage

  1. Install dependencies of the main project (global dependencies)

    1. Navigate to the folder where the project has been cloned
    2. Run yarn
  2. Install all the sub-project dependencies with yarn dependencies

  3. Generate types (GraphQL service), specs and routes (OpenAPI service) by running yarn generated

  4. Build all the services TS files with yarn building

  5. Run the services with the command yarn startup:services

    1. GraphQL service (People): http://localhost:3001/graphql
    2. OpenAPI service (Employment): http://localhost:3002/docs

These are the default port values defined in the .env file in the main project folder.

These services need to be up and running for the stitching service to run!

  1. Run a gateway
    1. Stitching Gateway: yarn startup:stitching-gateway (http://localhost:3003/graphql)
    2. Mesh Gateway: yarn startup:mesh-gateway (http://localhost:400/graphql) (*)

(*) The Mesh Gateway should be running in the port configured in the .env file (3004) but GraphQL Mesh does't seem to correctly pickup the environment variable for the port override.

Known issues

Failing queries in the Stitching Gateway

When running a query against the gateway:

query getPeople {
  GraphQLService {
    people {
      id
    }
  }
}

The following error occurs:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Query.GraphQLService.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "GraphQLService"
      ]
    }
  ],
  "data": null
}

Partial learnings and conclusions

  • No examples of stitching schemas at build time could be found in the GraphQL Tools documentation, so this project is an attempt of an implementation for this use case.

  • The gateway configuration is inherently wrong, since the incoming requests should be processed by executors that relay the queries to the corresponding downstream APIs instead of using resolvers.

  • The stitched schema is created using transforms that allow defining namespaces for the different schemas to avoid collisions. When initializing the gateway, it should also be possible to route incoming queries to the corresponding downstream API via executors. However, it's not obvious how to specify transforms when configuring the gateway with the stitched schema.

graphql-build-time-stitching's People

Contributors

cweckesser 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.