Skip to content

mjfaga/node-froid-example

Repository files navigation

Demo Repo for @wayfair/node-froid

Table of Contents

Getting Started

Installation

  1. Install dependencies:
    yarn install

Generating the Froid schema

  1. Trigger the generate command
    yarn generate:froid # generates to ./src/sample/froid/schema.graphql

NOTE: For convenience, this is already completed if you use the main branch of this repo

Setting up your Managed Federation Graph

  1. Set up a new Graph in with a Graph Architecture = Supergraph (the default)
  2. Run the rover scripts below to push all subgraph schemas in this demo to your supergraph
rover subgraph publish <your-graph-id>@source --schema ./src/sample/marketplace-listings/schema.graphql --name marketplace-listing-service --routing-url http://localhost:5001/graphql
rover subgraph publish <your-graph-id>@source --schema ./src/sample/reviews/schema.graphql --name reviews-service --routing-url http://localhost:5002/graphql
rover subgraph publish <your-graph-id>@source --schema ./src/sample/froid/schema.graphql --name froid-service --routing-url http://localhost:5000/graphql

Running the demo

  1. Copy the .env.example
    cp .env.example .env
  2. Update the .env with:
    • APOLLO_KEY: The service key value from Apollo Studio
    • GRAPH_ID: The id of the federated graph you set up in Apollo Studio
    • GRAPH_VARIANT: The name of the variant you want to run based on your Apollo Studio configuration
  3. Start all of the services:
    yarn start
  4. Navigate to http://localhost:4000/graphql to access the gateway playground

Sample Queries

Reviews Connection Query

query MarketplaceListingReviews(
  $first: Int
  $after: String
  $listingId: String!
) {
  marketplaceListing(listingId: $listingId) {
    id
    name
    reviews(first: $first, after: $after) {
      totalCount
      pageInfo {
        hasNextPage
        endCursor
      }
      edges {
        cursor
        node {
          id
          title
          rating
        }
      }
    }
  }
}

Variables

{
  "first": 2,
  "after": null,
  "listingId": "W003547033"
}

node Query

query SimilarMarketplaceListings($nodeId: ID!) {
  node(id: $nodeId) {
    __typename
    id
    ... on MarketplaceListing {
      name
      similarListings {
        id
        name
      }
    }
  }
}

Variables

{
  "nodeId": "TWFya2V0cGxhY2VMaXN0aW5nOnsibGlzdGluZ0lkIjoiVzAwMzU0NzAzMyJ9"
}

About

Examples for @wayfair/node-froid usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published