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 raw response with selections on abstract type #4775

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tobias-tengler
Copy link
Contributor

@tobias-tengler tobias-tengler commented Aug 20, 2024

Previously all selections done on abstract types, would be generated as required properties in the raw response type.
This PR tracks all selections on abstract types separately and only makes them required if the concrete type implements the abstract type. The change in the generated types can be seen in this diff.

To enable a gradual rollout, a disable_more_precise_abstract_selection_raw_response_type feature flag has been added that allows to opt operations out of the new raw response type generation.

@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch from b883382 to 32f5717 Compare September 6, 2024 08:04
@tobias-tengler
Copy link
Contributor Author

@captbaritone Thoughts on this?

@captbaritone
Copy link
Contributor

This looks more correct to me at first glance! Thanks for working on this. I likely won't have time to look into it more closely until after GraphQL conf. One thing we'll have to look out for is if this will cause type errors with existing places people are using raw response types and how we'll manage that rollout if it's the case.

Let me see if anyone else on the team can take a look before then.

@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch 2 times, most recently from b2a047c to 97221cb Compare September 17, 2024 19:04
@tobias-tengler
Copy link
Contributor Author

@captbaritone This will certainly lead to type errors for existing projects. I've added a feature flag to enable an opt-out.

@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch from 97221cb to 45b2e04 Compare September 20, 2024 19:07
@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch from 45b2e04 to 2be6f8c Compare October 15, 2024 18:15
@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch from 2be6f8c to af3c1c4 Compare October 20, 2024 15:27
@tobias-tengler tobias-tengler force-pushed the fix-raw-response-with-selections-on-abstract-type branch from af3c1c4 to a5db816 Compare January 21, 2025 17:52
@tobias-tengler
Copy link
Contributor Author

@captbaritone Could we land this?

@@ -120,6 +142,7 @@ pub(crate) struct RawResponseFragmentSpread {
pub(crate) value: StringKey,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there actually cases where a selection (like this one or the ones below) actually have both a concrete type and an abstract type? My reading of this PR is that we expect to have only one or the other or neither. Is my reading correct? If it is, could we collapse this to an option of an enum with two variants?

.get_object_id()
.map(|id| typegen_context.schema.object(id))
{
for (abstract_type, abstract_selections) in &by_abstract_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get a comment explaining the case we are handling here?

if !base_fields.is_empty() || !by_abstract_type.is_empty() {
let mut base_fields_map = selections_to_map(base_fields.clone().into_iter(), false);

if !by_abstract_type.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get a comment explaining the case we are handling here?

@tobias-tengler
Copy link
Contributor Author

@captbaritone Thanks for the review!
One more question: Do you need a feature flag to turn of this addition at Meta? I just added one because I thought it's the kind of change you guys would want to have a flag for, but if you don't, I'll gladly get rid of it 😆

@captbaritone
Copy link
Contributor

Do you need a feature flag to turn of this addition at Meta?

I suspect we will.

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

Successfully merging this pull request may close these issues.

3 participants