Skip to content

Simplify directive mutation#967

Merged
goto-bus-stop merged 4 commits intoapollographql:mainfrom
tninesling:mutability-support
Apr 23, 2025
Merged

Simplify directive mutation#967
goto-bus-stop merged 4 commits intoapollographql:mainfrom
tninesling:mutability-support

Conversation

@tninesling
Copy link
Copy Markdown
Contributor

@tninesling tninesling commented Apr 18, 2025

Implements mutable versions of some functions used to access directives and their arguments. This improves the ergonomics for some of the composition work we're doing in apollographql/router#7235.

@tninesling tninesling requested a review from a team as a code owner April 18, 2025 02:15
Comment on lines +147 to +151
impl<T: Clone> std::ops::DerefMut for Node<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.make_mut()
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The rest of this PR looks great but this change feels a bit "too magical" since it can make it invisible when a subtree stops being shared. Maybe that’s not so bad: our nodes don’t use interior mutability so sharing v.s. not wouldn’t change behavior and is "only" a performance concern. But it’s a departure from usual Rust conventions.

@goto-bus-stop what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fair. I think this probably does obfuscate the copy-on-write behavior a bit too much. This is trying to resolve some ergonomic issues we're having when we try to mutate parts of the schema, but it probably isn't the right solution. When we get a handle to some field, and we want to mutate something inside, it becomes .make_mut() all the way down.

We're specifically trying to mutate schemas in-place, so I am slightly worried about the possibility that we run into a case where we try to make some update and an unexpected clone causes that not to stick (admittedly, hiding the make_mut in this way just makes that worse). Is there a way for us to get a non-Arc-ed schema expressly for in-place mutation and then freeze it afterwards?

@goto-bus-stop goto-bus-stop enabled auto-merge (squash) April 23, 2025 07:27
@goto-bus-stop goto-bus-stop merged commit e938f4d into apollographql:main Apr 23, 2025
10 checks passed
@tninesling tninesling deleted the mutability-support branch April 23, 2025 14:22
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