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

fix: __typename when formatting response in some @interfaceObject cases #2530

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Feb 2, 2023

The introduction of @interfaceObject in federation 2.3 has for consequence that a subgraph (that uses an @interfaceObject) may return in its response a __typename that corresponds to an interface type in the supergraph (but which, locally to that subgraph, is an object type).

The idea is that if that __typename is requested, then the query planner will ensure that another follow-up fetch will override that value so it maps to a proper object type.

However, in some cases, that __typename is not queried, nor is there another reason to resolve the actual underlying implementation type of the underlying object (meaning that only fields of the interface are queried), and in that case the __typename may still point to the interface type when format_response is called. Unfortunately, that method currently nullify the whole object in such case, which is not the behaviour we want and was not caught in #2489.

Complete the checklist (and note appropriate exceptions) before a final PR is raised.

  • Changes are compatible[^1]
  • Documentation[^2] completed
  • Performance impact assessed and acceptable
  • Tests added and passing[^3]
    • Unit Tests
    • Integration Tests
    • Manual Tests

Notes

[^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]. Tick whichever testing boxes are applicable. If you are adding Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or ask for it to be labeled) as manual test

@pcmanus pcmanus force-pushed the response-format-itfObj-issue branch from 2a2c417 to 5872d0e Compare February 2, 2023 10:24
@abernix abernix requested a review from Geal February 3, 2023 10:01
Copy link
Contributor

@Geal Geal left a comment

Choose a reason for hiding this comment

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

one println to remove, otherwise it's good, thanks

@@ -150,6 +150,7 @@ impl Query {
variables: Object,
schema: &Schema,
) -> Vec<Path> {
println!("Formatting: {response:?}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
println!("Formatting: {response:?}");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. I've removed it and rebased (and updated to the new changelog thingy).

…oducted by `@interfaceObject`

The introduction of `@interfaceObject` in federation 2.3 has for
consequence that a subgraph (that uses an `@interfaceObject`) may return
in its response a `__typename` that corresponds to an interface type in
the supergraph (but which, locally to that subgraph, is an object type).

The idea is that if that `__typename` is requested, then the query
planner will ensure that another follow-up fetch will override that
value so it maps to a proper object type.

However, in some cases, that `__typename` is not queried, nor is there
another reason to resolve the actual underlying implementation type of
the underlying object (meaning that only fields of the interface are
queried), and in that case the `__typename` may still point to the
interface type when `format_response` is called. Unfortunately, that
method currently nullify the whole object in such case, which is not
the behaviour we want and was not caught in apollographql#2489.
@pcmanus pcmanus force-pushed the response-format-itfObj-issue branch from 5872d0e to 4d6b600 Compare February 6, 2023 08:54
@abernix abernix changed the title Fix handling of __typename when formatting response in some cases intr… fix: __typename when formatting response in some @interfaceObject cases Feb 8, 2023
@abernix abernix merged commit 4f6e3d7 into apollographql:dev Feb 8, 2023
abernix pushed a commit that referenced this pull request Feb 8, 2023
Resolves a snapshot test drift where the following two PRs passing
together resulted in this change being necessary, but not being caught
in the original contribution:

- #2530
- #2554 

Unblocks #2571
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.

3 participants