apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
818 stars 270 forks source link

feat: better error on schema generated w/invalid federation version #2678

Open EverlastingBugstopper opened 1 year ago

EverlastingBugstopper commented 1 year ago

Starting a Fed 2.2 router with a Fed 2.3 supergraph schema results in the following error message. Here's a one liner to reproduce:

$ curl -sSL https://rover.apollo.dev/nix/v0.10.0 | sh -s -- --force && export VERSION_DIR=/tmp/version-repro && export VERSION_FILE=$VERSION_DIR/schema.graphql && mkdir -p $VERSION_DIR && echo 'type Query {book(title: String!): Book} type Book { title: String }' > $VERSION_FILE | APOLLO_ROVER_DEV_COMPOSITION_VERSION=2.3.2 APOLLO_ROVER_DEV_ROUTER_VERSION=1.9.0 rover dev --name products --schema $FILE --url http://localhost:4000
downloading rover from https://github.com/apollographql/rover/releases/download/v0.10.0/rover-v0.10.0-x86_64-unknown-linux-gnu.tar.gz
writing binary to /home/avery/.rover/bin/rover
rover was successfully installed. Great!
If you would like to disable Rover's anonymized usage collection, you can set APOLLO_TELEMETRY_DISABLED=1
You can check out our documentation at https://go.apollo.dev/r/docs.
⚠️  Do not run this command in production! ⚠️  It is intended for local development.
🛫 starting a session with the 'products' subgraph
🎶 composing supergraph with Federation v2.3.2
ERROR: could not parse schema: Api("Invalid supergraph: uses unsupported join spec version v0.3 (supported versions: v0.2, v0.1)")

In this scenario, a better error message would be:

Invalid supergraph: schema was generated for Federation v2.3 which this router does not support. 
Please update your router to v1.10.0 or above. See https://www.apollographql.com/docs/router/federation-version-support/ for more information.

for context: check out this issue on the rover repo.


I would also like to discuss the possibility of starting the router anyway even if it doesn't fully understand the schema. In the above example for instance, there is no usage of any @interfaceObject directive, so presumably the schema is semi-routable. It would be great if we could instead print a warning if the versions are mismatched and only fail to start up if directives that are not understood are present in the schema.

BrynCooke commented 1 year ago

Let's restrict the scope to improving the error message. This can be done easily. Graceful degradation will be a big job.