Skip to content

Sample application to show GraphQL Federation with Apollo

Notifications You must be signed in to change notification settings

XPRTZ/hello-graphqlfederation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello GraphQL Federation

Setup

  • Clone the repository
  • Rename .env.sample to .env in the directories apps/gateway, apps/locations and apps/reviews
  • Run yarn install in the root of the repository
  • Run yarn dev to start the services all at once

Project structure

  • gateway: the Apollo Gateway which connects the subgraphs together. Available at http://localhost:4000

  • locations: the subgraph for Locations. Available at http://localhost:4001

  • reviews: the subgraph for revies. Available at http://localhost:4002

  • Api: contains the source of the data for both subgraphs. A simple REST server for Locations and Reviews. Available at localhost:3000

Usage

Open http://localhost:4000 and test the following queries

Get locations

This query gets data from only the locations subgraph.

query Locations {
  locations {
    id
    name
    description
  }
}

Latest Reviews

This query gets data from only the reviews subgraph.

query Locations {
  locations {
    id
    name
    description
  }
}

Latest Reviews With OverallRating

This query gets data from the reviews subgraph and adds data to location from within the reviews subgraph. The added data runs in the context of reviews.

query LatestReviewsWithOverallRating {
  latestReviews {
    id
    comment
    rating
    location {
      name
      overallRating
      reviewsForLocation {
        comment
      }
    }
  }
}

Reviews for location

This query get data for locations but from the reviews subgraph. This runs in the context of locations.

query ReviewsForLocations {
  locations {
    reviewsForLocation {
      comment
      rating
    }
    overallRating
  }
}

About

Sample application to show GraphQL Federation with Apollo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published