Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No actionable error message on locally missing subgraph type (supergraph compose) #42

Closed
dchambers opened this issue Feb 1, 2022 · 5 comments

Comments

@dchambers
Copy link

supergraph compose fails with no actionable error messages when a subgraph depends on a type that it does not define, but which some other subgraph does.

For example, given a.graphql:

extend type Query {
  fieldA: Uri
}

and b.graphql:

extend type Query {
  fieldB: Uri
}

scalar Uri

and a supergraph.yml config file pointing at these files:

subgraphs:
  films:
    routing_url: https://a.example.com
    schema:
      file: ./a.graphql
  people:
    routing_url: https://b.example.com
    schema:
      file: ./b.graphql

then we get:

rover supergraph compose --config supergraph.yml
error[E029]: Encountered 1 build error while trying to build a supergraph.

Caused by:
    Something went wrong! No build errors were recorded, but we also build a valid supergraph SDL.
    
        The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.

This leads to the end-developer needing to perform a binary search, which is hard with an SDL because you have to be careful not to remove types that are depended on by other types, otherwise you get completely different errors.

@abernix
Copy link
Member

abernix commented Feb 23, 2022

@EverlastingBugstopper Thoughts? I know we've tweaked some of this functionality recently. Should we move this into federation-rs and track it there?

@EverlastingBugstopper
Copy link
Contributor

EverlastingBugstopper commented Feb 23, 2022

Possibly should move to federation-rs for the error message improvement. it looks like this would have produced a "graphql error" rather than a composition error, and i don't think that federation-rs currently handles that.

i have a reproduction repo here that emits the following error message:

$ npm run start

> [email protected] start
> npm run compile && node ./dist/index.js


> [email protected] compile
> tsc

{
  errors: [
    GraphQLError: [a] Unknown type Uri
        at Object.err (/home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/error.js:11:87)
        at /home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/federation.js:593:25
        at Array.map (<anonymous>)
        at addSubgraphToError (/home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/federation.js:585:61)
        at buildSubgraph (/home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/federation.js:434:19)
        at Subgraphs.add (/home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/federation.js:530:99)
        at subgraphsFromServiceList (/home/avery/work/fed-repro/node_modules/@apollo/federation-internals/dist/federation.js:509:23)
        at composeServices (/home/avery/work/fed-repro/node_modules/@apollo/composition/dist/compose.js:35:75)
        at main (/home/avery/work/fed-repro/dist/index.js:24:46)
        at Object.<anonymous> (/home/avery/work/fed-repro/dist/index.js:26:13) {
      path: undefined,
      locations: undefined,
      extensions: [Object]
    }
  ]
}

IIRC we only check for CompositionSuccess or CompositionFailure and this seems more like an exception was thrown. This then gets serialized as "1" error, but since it doesn't know what to do it says "we dont know what to do". it should probably just try to call .toString() on the error.

@EverlastingBugstopper EverlastingBugstopper transferred this issue from apollographql/federation Feb 23, 2022
@abernix
Copy link
Member

abernix commented Feb 23, 2022

This could also be a bug in Federation 0.x composition. I wonder if this is improved in Federation 2?

@EverlastingBugstopper
Copy link
Contributor

EverlastingBugstopper commented Feb 23, 2022

this is using federation 2 i believe? @apollo/[email protected] in that repro repo. proof

@EverlastingBugstopper
Copy link
Contributor

This is (mostly) fixed in Rover 0.4.5. Output looks like this for fed 1 and fed 2 respectively.

fed1 output is still a bit janky, i'm thinking we'll need to update the harmonizer-js lib to spit out [{message: e.toString()}] rather than just [err] for those errors that say "an unknown error occurred during the build". i've opened #70 to further fix this up.

$ rover supergraph compose --config ./examples/federation-rs/issue-42/supergraph.yaml     
error[E029]: Encountered 6 build errors while trying to build a supergraph.

Caused by:
    Encountered 6 build errors while trying to build the supergraph.
    UNKNOWN: An unknown error occurred during the build.
    UNKNOWN: An unknown error occurred during the build.
    UNKNOWN: Unknown type "Uri".
    UNKNOWN: Field "Query.fieldA" can only be defined once.
    UNKNOWN: Unknown type "Uri".
    UNKNOWN: Type Query must define one or more fields.
    
        The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.
$ rover fed2 supergraph compose --config ./examples/federation-rs/issue-42/supergraph.yaml 
error[E029]: Encountered 2 build errors while trying to build a supergraph.

Caused by:
    Encountered 2 build errors while trying to build the supergraph.
    UNKNOWN: [films] Unknown type Uri
    UNKNOWN: [people] Unknown type Uri
    
        The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants