Giter Site home page Giter Site logo

federation-2-readiness's Introduction

Federation 2 Readiness

Check your federated schema for backward-compatibility with Federation 2 and audit query plans.

The code in this repository is experimental and has been provided for reference purposes only. Community feedback is welcome but this project may not be supported in the same way that repositories in the official Apollo GraphQL GitHub organization are. If you need help you can file an issue on this repository, contact Apollo to talk to an expert, or create a ticket directly in Apollo Studio.

Usage

Basic Usage

Requires a user API key (created in Personal Settings), not a graph API key.

export APOLLO_KEY=<your apollo api key>
npx github:@apollosolutions/federation-2-readiness
# follow prompts to select a graph, a variant, and a time window for operations

Example output:

? Select Graph mygraph
๐ŸŽ‰ Composed successfully
? Audit Operations in the Last Day
-----------------------------------
โœ… Operations audited: 9
๐Ÿ† Operations that match: 9

Generate Query Plan Reports

export APOLLO_KEY=<your apollo api key>
npx github:@apollosolutions/federation-2-readiness --out results
# follow prompts to select a graph, a variant, a time window for operations

Example report in results/MyOperation-a1b2c3.md:

MyOperation a1b2c3
==================
https://studio.apollographql.com/graph/mygraph/operations?query=a1b2c3&queryName=MyOperation&variant=current

๐Ÿ’ฃ Query plans differ

Diff
----
- Expected
+ Received

  QueryPlan {
    Sequence {
      Fetch(service: "products") {
        {
          product(id: $productId) {
            __typename
            id
            dimensions {
              size
+             weight
            }
          }
        }
      },
      Flatten(path: "product") {
        Fetch(service: "shipping") {
          {
            ... on Product {
              __typename
              id
              dimensions {
                size
+               weight
              }
            }
          } =>
          {
            ... on Product {
              shippingCost {
                value
              }
            }
          }
        },
      },
    },
  }

Resolve Composition Errors

If you encounter a composition error, you can run the audit against local subgraph files. The process is:

  1. Generate a local supergraph config.
  2. Download subgraph SDL files and point the supergraph config to use them.
  3. Run the audit command using the local supergraph config instead of Studio.
npx github:@apollosolutions/federation-2-readiness config init --out supergraph.yaml
# follow prompts to select the graph and variant

npx github:@apollosolutions/federation-2-readiness config extract --config supergraph.yaml --out subgraphs
# follow prompts to select the subgraphs to extract to local files

npx github:@apollosolutions/federation-2-readiness --config supergraph.yaml

Known Limitations

  • Published only as source code to Github. Not available on NPM.
  • The versions of Fed 1 and Fed 2 composition may not match what's running in Apollo Studio or Rover.
  • Known query plan serialization differences include:
    • List arguments being serialized as "" in Federation 1 and [""] in Federation 2.

federation-2-readiness's People

Contributors

dependabot[bot] avatar lennyburdette avatar parkerholladay avatar pcmanus avatar smyrick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

federation-2-readiness's Issues

"Internal Error: Invalid query plan" error when running tool.

Hi! First, huge thanks for providing this. Already caught an issue for us with graph composition.

I'm running into an error when generating output using the --out option. It runs successfully without the option, but fails with it set. I'm concerned that it may not be producing output for every operation it finds, but I can't tell which operation is causing the issue.

Unset:

$ npx github:@apollosolutions/federation-2-readiness
? Select Graph mygraph
? Select Variant production
โœ… Schema composes with Federation v1
โœ… Schema composes with Federation v2
? Use the same graphRef? mygraph@production Yes
? Audit Operations in the Last Day
-----------------------------------
โœ… Operations audited: 335
๐Ÿ† Operations that match: 304
โŒ Operations with differences: 31

Add --out <directory> to print reports for each operation.

--out set:

โฏ npx github:@apollosolutions/federation-2-readiness --out readiness-output/
? Select Graph mygraph
? Select Variant production
โœ… Schema composes with Federation v1
โœ… Schema composes with Federation v2
? Use the same graphRef? mygraph@production Yes
? Audit Operations in the Last Day
-----------------------------------
โœ… Operations audited: 335
๐Ÿ† Operations that match: 304
โŒ Operations with differences: 31
Internal Error: Invalid query plan
    at queryPlanToMermaid (file:///Users/me/.npm/_npx/32197df7ba70c1ce/node_modules/@apollosolutions/federation-2-readiness/src/federation/queryPlanToMermaid.js:100:11)
    at AuditCommand.execute (file:///Users/me/.npm/_npx/32197df7ba70c1ce/node_modules/@apollosolutions/federation-2-readiness/src/commands/audit.js:391:15)
    at async AuditCommand.validateAndExecute (/Users/me/.npm/_npx/32197df7ba70c1ce/node_modules/clipanion/lib/advanced/Command.js:73:26)
    at async Cli.run (/Users/me/.npm/_npx/32197df7ba70c1ce/node_modules/clipanion/lib/advanced/Cli.js:222:24)
    at async Cli.runExit (/Users/me/.npm/_npx/32197df7ba70c1ce/node_modules/clipanion/lib/advanced/Cli.js:231:28)

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.