Skip to content

feat(router): Response Reformatting Errors#8441

Merged
TylerBloom merged 21 commits intodevfrom
tylerb/router-1425
Oct 21, 2025
Merged

feat(router): Response Reformatting Errors#8441
TylerBloom merged 21 commits intodevfrom
tylerb/router-1425

Conversation

@TylerBloom
Copy link
Contributor

@TylerBloom TylerBloom commented Oct 17, 2025


This PR adds logic to insert errors into response if parts of a subgraph response are incorrect and get reformatted. This corrects and addresses prior response reformatting tests.

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

@TylerBloom TylerBloom requested a review from a team October 17, 2025 02:47
@apollo-librarian
Copy link

apollo-librarian bot commented Oct 17, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: bc302854ab0c298aeb5c5cef
Build Logs: View logs

@github-actions

This comment has been minimized.

Copy link
Contributor Author

@TylerBloom TylerBloom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to clearing up the wording for some of the errors, there is also an open question around if all possible invalid objects need to be validated. That is, do all elements in arrays and fields in object need to be validated if an invalid, non-nullable object is found?

Copy link
Contributor

@aaronArinder aaronArinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass! talking synchronously about the logic will help me understand it better; then, I'll spend some time with the tests--it looks like there's good coverage, but I'll need to open it in an editor to really see what's covered

}
}
#[inline]
fn format_non_nullable_value<'a: 'b, 'b>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more me learning about rust than about this pr; but, it looks like these two lifetimes are just the same lifetime, do we need 'a: 'b, could 'b just be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do need 'a to outlive 'b (i.e. 'a: 'b) due to some lifetime rules around subtyping and variance. Notably, if this didn't require &mut Vec<_> and just had &[_] instead, we wouldn't be needed to specify any lifetimes and everything could just be elided.

Comment on lines +795 to +809
// NOTE: The subtype logic is strange. We are trying to determine if a fragment
// should be applied, but we don't have the __typename of the selection set
// (otherwise, we would be on a different branch). Consider the following query
// for a union Thing = Foo | Bar:
// { thing { ... on Foo { foo }, ... on Bar { bar } } }
//
// As we process the `... on Foo` fragment, `Foo` is `type_condition` and
// `Thing` is `current_type`, we *could* reverse the order in calling
// `is_subtype` and apply the fragment; however, the same is true for the `Bar`
// fragment. Without the type info of the data we have in our response, we
// can't know which to apply (or if both should apply in the case of
// interfaces).
//
// Without that information, this is the best we can do without construction a
// much more complicated reformatting heuristic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 👍 👍 👍 so nice

Comment on lines 1276 to 1275
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of like the field Thing.i as a way to understand where to find the invalid value; is there a way to keep the directional help for the field but also include the type that went wrong? Something like Invalid value found for field Thing.i, type Int?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the Type.field was changed is because we include the full path with the message. It also makes the message consistent between objects and lists while allowing full info to be available in the path in both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably, Renee and I came to an agreement on this message convention.

@TylerBloom TylerBloom requested a review from a team as a code owner October 21, 2025 17:56
Copy link
Contributor

@aaronArinder aaronArinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@TylerBloom TylerBloom enabled auto-merge (squash) October 21, 2025 19:06
@TylerBloom TylerBloom merged commit f650b8a into dev Oct 21, 2025
15 checks passed
@TylerBloom TylerBloom deleted the tylerb/router-1425 branch October 21, 2025 19:08
@abernix abernix mentioned this pull request Oct 27, 2025
abernix added a commit that referenced this pull request Oct 28, 2025
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

Successfully merging this pull request may close these issues.

2 participants