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

add the operation kind to FetchNode #1427

Merged
merged 4 commits into from
Feb 10, 2022
Merged

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Jan 24, 2022

Fix #1423

this will allow data sources to decide if they can cache or deduplicate
a request

this will allow data sources to decide if they can cache or deduplicate
a request
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 24, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

This PR LGTM (I left one review comment), but I'll defer to other reviewers (and I'll add @pcmanus as a requested reviewer).

My one suggestion not related to the code is that I'd update the PR body with a bit of additional "motivation" that says: "...without needing to parse the operation to find out".

Anyhow, that's just a nit. @pcmanus, @martijnwalraven, what do you think?

@@ -801,6 +801,7 @@ class FetchGroup {
requires: inputNodes ? trimSelectionNodes(inputNodes.selections) : undefined,
variableUsages: this.selection.usedVariables().map(v => v.name),
operation: stripIgnoredCharacters(print(operation)),
operationKind: (operation.definitions[0] as OperationDefinitionNode).operation,
Copy link
Member

Choose a reason for hiding this comment

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

This is the only thing I find myself scrutinizing at a high-level — though I haven't checked this branch out to look more closely so apologies if this is obvious to others:

Is there a guarantee that the (first) operation definition that this points to is indeed the operation that's being executed? In a non-GraphQL query, I would be worried about this since the operation that we'd actually execute would be determined by the operationName, but since this is probably a generated query and we probably don't generate multi-operation documents, it's probably fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not seen batching on subgraph requests, but I might be wrong on that

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 could be replaced with a more explicit "has_mutations", maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

There cannot be multiple operations, but there can be fragments. As it happens, the code currently guarantees the operation will be first in that case so the code would work as is, but it's fragile to rely on it and I'd rather change that line. The shortest solution is probably just:

operationKind: this.isEntityFetch ? 'query' : this.rootKind

but the "cleanest" solution, which is not much more complicated, is probably to change operationForEntitiesFetch and operationForQueryFetch to return the Operation directly, and then to have:

const fetchNode: FetchNode = {
  ...,
  operation: stripIgnoredCharacters(print(operationToDocument(operation))),
  operationKind: operation.rootKind
};

Happy to write the commit for what if you prefer, though I'm just you shouldn't have much difficulty :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 0e6e535
@pcmanus thank you for pointing me to the right part of the code :)

@abernix abernix requested a review from pcmanus January 26, 2022 13:42
Copy link
Contributor

@pcmanus pcmanus 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 to me.

query-planner-js/src/buildPlan.ts Outdated Show resolved Hide resolved
@Geal Geal merged commit 17b9ca5 into main Feb 10, 2022
@Geal Geal deleted the geal-add-operation-kind-to-fetchnode branch February 10, 2022 15:57
abernix added a commit to apollographql/federation-rs that referenced this pull request Feb 14, 2022
This is expected since the [Ref]erenced PR introduced it!

Ref: apollographql/federation#1427
abernix added a commit to apollographql/federation-rs that referenced this pull request Feb 14, 2022
* router-bridge: Update to `@apollo/query-planner@2.0.0-alpha.6`

Most notably to bring in apollographql/federation#1511

Ref: apollographql/federation@ee84b3fd9df161c3a94

* tests: update snapshots to include `operationKind`

This is expected since the [Ref]erenced PR introduced it!

Ref: apollographql/federation#1427
trevor-scheer added a commit that referenced this pull request Mar 17, 2022
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.

FetchNode should contain the operation type
3 participants