Coder Social home page Coder Social logo

anton-iades / graphql-samples Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 62 KB

An illustration of Apollo Federation using Apollo Gateway and GraphQL .NET

License: MIT License

C# 91.71% JavaScript 3.46% Dockerfile 4.82%
graphql dotnet-core dotnet mediatr apollo-server apollo-gateway nodejs

graphql-samples's Introduction

graphql-samples

Apollo Federation with GraphQL.NET

Using Apollo Federation, we are composing a single unified data graph whose implementation has been federated across three independent GraphQL APIs - each one responsible for implementing only the part of the graph that it is responsible for.

The services have been split up by concern - not by type - which is made possible by schema type extensions and schema type referencing. For example, the core Movie type is defined in the Movie Studio API, but it is being extended by the Movie Reviews API (adds thereviews field) and the Movie type is being referenced in the Session type defined in the Movie Theatre API.

The gateway is a NodeJS application that uses Apollo Gateway with Express.js integration to compose the distinct schemas into a single federated graph and to execute queries across the implementing services.

The GraphQL APIs have been implemented in .NET, however they are compatible with GraphQL APIs that are implemented in any language that also supports the Apollo Federation spec e.g. Apollo Server (NodeJS).

You can also opt to keep the default controller middleware in .NET which will allow your API to support both REST and GraphQL at the same time. E.g. GraphQL at /gql and REST at /api/[controller]/[action].

Implementing services

The following is a list of the implementing services and a link to their partial schema:

The implementing services are registered in the Apollo Gateway constructor in index.js

Dependencies

  • Docker Engine
  • Docker Compose

Run

Use docker compose to start up the implementing services and the gatway

docker-compose up --build -d

The composed schema can be visualised by navigating to http://localhost:4000/voyager

The GraphQL Playground can be accessed by navigating to http://localhost:4000/graphql

Sample query that spans all 3 implementing services (click on Query Plan to see execution plan)

{
  nextSession {
    theatre
    time
    movie {
      title
      genres
      released
      cast {
        name
      }
      reviews {
        stars
        message
        containsSpoilers
      }
    }
  }
}

Stop the services

docker-compose stop

graphql-samples's People

Contributors

anton-iades avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

x4m1

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.