Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Query Graph Traversal: Part 2 #161

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

sachindshinde
Copy link
Contributor

Fixes #155

@sachindshinde sachindshinde force-pushed the sachin/query-graph-traversal-part-2 branch 3 times, most recently from a2cec85 to 4e422fa Compare February 2, 2024 16:00
@sachindshinde sachindshinde marked this pull request as ready for review February 2, 2024 16:01
@sachindshinde sachindshinde force-pushed the sachin/query-graph-traversal-part-2 branch from 4e422fa to a688086 Compare February 2, 2024 21:48
@@ -141,3 +142,21 @@ pub(crate) fn directive_required_boolean_argument(
.into()
})
}

pub(crate) fn directive_optional_variable_boolean_argument(
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m thinking we could use a trait for this kind of conversion, but probably not in this PR. (Rather in a larger design for apollographql/apollo-rs#717)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, having something cleaner/simpler here would be nice (ideally with some way to handle custom scalars).

pub(crate) fn unsatisfied_conditions() -> Self {
Self {
satisfied: false,
cost: -1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is cost signed? What does negative cost mean? If -1 is the only negative value with special meaning different from "minus one", should it be Option::None instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should never be used directly if it's -1 I think. I ended up refactoring this into an enum instead, so cost vanishes in the unsatisfied case.

/// If the trigger of the last edge in the `edges` array was an operation element with a
/// `@defer` application, then the arguments of that application.
defer_on_tail: Option<DeferDirectiveArguments>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
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
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, derive_more::From)]

We already depend on this derive macro crate, which I think can replace the two impls below.

Comment on lines +168 to +160
// atomically increment global counter
Self(NEXT_OVERRIDE_ID.fetch_add(1, atomic::Ordering::AcqRel))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever plan on (de)serializing something that contains OverrideId? That could lead to collisions. Maybe add a comment on the struct to warn against adding derive(Serialize, Deserialize) without changing new() to do something else like UUIDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, we shouldn't be serializing/deserializing these AFAIK. Will add a warning in a comment.

Comment on lines 430 to 432
// PORT_NOTE: The JS codebase found all matching candidates and asserted there was only one.
// We consider it unlikely for there to be more than one candidate given all the code paths
// that create edges, so we've removed the assert here and return on the first match.
Copy link
Contributor

Choose a reason for hiding this comment

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

We could still assert (or debug assert) there isn’t a second candidate without collecting all of them:

let mut iter = /* … */;
if let Some(first) = iter.next() {
    debug_assert!(iter.next().is_none(), "unexpectedly found multiple candidates")
    // …
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a nice pattern, will add the debug_assert!()!

_source: &NodeStr,
_interface_field_definition_position: InterfaceFieldDefinitionPosition,
) -> Result<bool, FederationError> {
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

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

we’ll definitely need to grep the entire code base for FIXME/TODO/todo! at some point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, most of the todo!()s in this PR are just blocked by not having an easy way to get subgraph info, so I'm going to file a follow-up PR for that.

Comment on lines +41 to 48
pub(crate) fn new() -> Self {
// atomically increment global counter
Self(NEXT_ID.fetch_add(1, atomic::Ordering::AcqRel))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above for OverrideId re serialization

pub(crate) fn defer_directive_arguments(
&self,
) -> Result<Option<DeferDirectiveArguments>, FederationError> {
if let Some(directive) = self.directives.get(&name!("defer")) {
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
if let Some(directive) = self.directives.get(&name!("defer")) {
if let Some(directive) = self.directives.get("defer") {

I think this should be equivalent

@sachindshinde sachindshinde force-pushed the sachin/query-graph-traversal-part-2 branch from f31778b to 84b2483 Compare February 6, 2024 20:05
@sachindshinde sachindshinde merged commit 315cd15 into main Feb 6, 2024
7 checks passed
@sachindshinde sachindshinde deleted the sachin/query-graph-traversal-part-2 branch February 6, 2024 20:09
SimonSapin pushed a commit to apollographql/router that referenced this pull request May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Graph Traversal] advance graph path of operation element
2 participants