Skip to content

Commit

Permalink
Handle unresolved elements gracefully
Browse files Browse the repository at this point in the history
Fixes #376

Co-authored-by: Sylvain Lebresne <[email protected]>
  • Loading branch information
mduesterhoeft and Sylvain Lebresne committed Jan 3, 2022
1 parent 13a8091 commit 78a20b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- _Nothing to see here. Stay tuned._
- Continue resolving when an `@external` reference cannot be resolved. [#376](https://github.com/apollographql/federation/issues/376)

## v0.45.0

Expand Down
12 changes: 11 additions & 1 deletion gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,17 @@ function executeSelectionSet(
const selections = (selection as QueryPlanFieldNode).selections;

if (typeof source[responseName] === 'undefined') {
throw new Error(`Field "${responseName}" was not found in response.`);
// This method is called to collect the inputs/requires of a fetch. So, assuming query plans are correct
// (and we have not reason to assume otherwise here), all inputs should be fetched beforehand and the
// only reason for not finding one of the inputs is that we had an error fetching it _and_ that field
// is non-nullable (it it was nullable, error fetching the input would have make that input `null`; not
// having the input means the field is non-nullable so the whole entity had to be nullified/ignored,
// leading use to not have the field at all).
// In any case, we don't have all the necessary inputs for this particular entity and should ignore it.
// Note that an error has already been logged for whichever issue happen while fetching the inputs we're
// missing here, and that error had much more context, so no reason to log a duplicate (less useful) error
// here.
return null;
}
if (Array.isArray(source[responseName])) {
result[responseName] = source[responseName].map((value: any) =>
Expand Down

0 comments on commit 78a20b2

Please sign in to comment.