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

FED-189: port extractDeferFromOperation #284

Merged
merged 3 commits into from Apr 29, 2024
Merged

FED-189: port extractDeferFromOperation #284

merged 3 commits into from Apr 29, 2024

Conversation

duckki
Copy link
Contributor

@duckki duckki commented Apr 26, 2024

Implemented extract_defer_from_operation function.

Even though most of its functionality won't be used until @defer is actually implemented, it's called from compute_nodes_for_op_path_element and we would've needed some implementation anyways. So, I ported all of it.

@duckki duckki self-assigned this Apr 26, 2024
@duckki duckki removed their assignment Apr 26, 2024
@duckki duckki marked this pull request as draft April 26, 2024 21:50
- `register_defer` call was previously missed.
- removed DeferDirectiveArgs, in favor of DeferDirectiveArguments
- removed FetchDependencyGraphPath, in favor of FetchDependencyGraphNodePath
@duckki duckki marked this pull request as ready for review April 27, 2024 00:59
@duckki
Copy link
Contributor Author

duckki commented Apr 27, 2024

About the FetchDependencyGraphPath => FetchDependencyGraphNodePath change, see my Slack discussion with Sachin.

Copy link
Contributor

@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.

Looks good overall, just a few places to be cleaned up, I think. :)

Comment on lines 13 to 14
pub(crate) label: Option<NodeStr>,
pub(crate) if_: Option<BooleanOrVariable>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if there is a reason for these being private. It seems like there were just two spots that make use of this change. One of those places can be replaced with an existing method. The other can be simplified to not need to use a struct literal.

Suggested change
pub(crate) label: Option<NodeStr>,
pub(crate) if_: Option<BooleanOrVariable>,
label: Option<NodeStr>,
if_: Option<BooleanOrVariable>,

Comment on lines 339 to 347
// Note: @defer is not repeatable.
inline_fragment.data().directives.get("defer").map(|defer| {
let label: Option<NodeStr> = defer
.argument_by_name("label")
.and_then(|label| label.as_node_str().cloned());
let if_ = directive_optional_variable_boolean_argument(defer, &name!("if"))
.unwrap_or_default();
DeferDirectiveArguments { label, if_ }
})
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already a method for this on NormalizedInlineFragmentData, so you can replace all of this with:

Suggested change
// Note: @defer is not repeatable.
inline_fragment.data().directives.get("defer").map(|defer| {
let label: Option<NodeStr> = defer
.argument_by_name("label")
.and_then(|label| label.as_node_str().cloned());
let if_ = directive_optional_variable_boolean_argument(defer, &name!("if"))
.unwrap_or_default();
DeferDirectiveArguments { label, if_ }
})
inline_fragment.data().defer_directive_arguments().ok().flatten()

Comment on lines 205 to 206
pub(crate) path_in_node: Arc<OpPath>,
pub(crate) response_path: Vec<FetchDataPathElement>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's limit visibility for fields that don't need to be made public.

Suggested change
pub(crate) path_in_node: Arc<OpPath>,
pub(crate) response_path: Vec<FetchDataPathElement>,
path_in_node: Arc<OpPath>,
response_path: Vec<FetchDataPathElement>,

return Ok((Some(operation.clone()), updated_context));
};

let Some(ref updated_defer_ref) = defer_args.label else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the existing label method:

Suggested change
let Some(ref updated_defer_ref) = defer_args.label else {
let Some(updated_defer_ref) = defer_args.label() else {

Comment on lines 2450 to 2452
return Err(FederationError::internal(
"All defers should have a label at this point",
));
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is more stylistic, but using Option::ok_or_else + a try operator (i.e. ?) is often an easier-to-read way of short-circuiting a function that returns a Result when you have an Option. Not a necessary change, as both ways will compile to basically the same thing, but I figured I would mention it.

@duckki
Copy link
Contributor Author

duckki commented Apr 29, 2024

@TylerBloom Thanks for the review! I just accepted your suggestions and pushed it.

@duckki duckki requested a review from TylerBloom April 29, 2024 17:54
Copy link
Contributor

@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.

LGTM 😄

@duckki duckki merged commit 5cb9ff5 into main Apr 29, 2024
7 checks passed
@duckki duckki deleted the duckki/FED-189 branch April 29, 2024 18:31
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.

None yet

2 participants