-
Notifications
You must be signed in to change notification settings - Fork 256
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
fix(gateway): Ignore thrown errors from extendSchema
#478
Conversation
@@ -514,6 +523,7 @@ export function addFederationMetadataToSchemaNodes({ | |||
// TODO: Why don't we need to check for non-object types here | |||
if (isObjectType(namedType)) { | |||
const field = namedType.getFields()[fieldName]; | |||
if (!field) break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen here in the new test case, when a type goes unrecognized, fields which return that type are abandoned. This handles the case where a field which is expected to exist cannot actually be found in the schema.
I think this is indeed a bit of an unconventional use of the That does make me wonder if we shouldn't also collect errors resulting from |
dcd9a9c
to
5f320ee
Compare
@@ -514,6 +523,7 @@ export function addFederationMetadataToSchemaNodes({ | |||
// TODO: Why don't we need to check for non-object types here | |||
if (isObjectType(namedType)) { | |||
const field = namedType.getFields()[fieldName]; | |||
if (!field) break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break
was a mistake here, but corrected in #481
I suggested to Trevor on Slack that we do something more like
|
extendSchema
throws errors in the case that we extend a type before it exists during composition. This should certainly result in composition errors (which we have validations for), but it shouldn't causecomposeAndValidate
to throw, which is unexpected.This change catches and discards errors thrown by
extendSchema
. The reason for discarding and not capturing the error (Unknown type Bar.
) is that it's duplicated when we capture errors fromvalidateSDL
immediately after: https://github.com/apollographql/federation/blob/8f77bf41d8c5075ee1b5de6d7018a70326f39acd/federation-js/src/composition/compose.ts#L421In the
extendSchema
code path, there is only onethrow
case (excluding an initialassertSchema
which I'm not concerned about) and this test case exercises it. However, I'm unsure about this approach because there could be other errors thrown in the future which may be valuable or worth capturing. Open to feedback here, or possibly an alternative solution.Bit of an unrelated tangent here, but worth mentioning:
Modifying this area of the codebase made it tempting to return as early as possible once all errors are collected and stop returning both a schema and errors (which seems like odd behavior). However, we can provide more errors to the user when
compose
returns both, sincecomposeAndValidate
can take composition errors and append useful schema validation errors to the final set of errors provided.It wouldn't be unreasonable at some point to stop returning both a
schema
anderrors
fromcomposeAndValidate
, however (this is already what we do withcomposedSdl
).