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

Move some GraphQL analysis earlier in the pipeline #6128

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Oct 8, 2024

The following is now done in QueryAnalysisLayer instead of in the BridgeQueryPlanner service:

  • Finding the relevant operation in a GraphQL document based on operationName. Now ParsedDocument in context contains a reference to the parsed apollo_compiler::executable::Operation.
  • Scan that operation’s root fields to find which are present: root __typename, schema intropsection, and "normal" non-meta fields. This is a preliminary step to moving introspection out of BridgeQueryPlanner.

As a side-effect observable to clients, the exact response for some error cases like an empty document changes slightly as the error no longer comes from JavaScript code.

Also optional drive-by refactor in the second commit: change spec::Query to contain a single Operation instead of a Vec<Operation>. This removes conditionals and the need to pass operationName around in a lot of places, notably in execution code.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

A GraphQL document can contain multiple operations, but exactly one of them
is relevant for a given request as specified by `operationName`.
@SimonSapin SimonSapin requested review from a team as code owners October 8, 2024 09:31
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Oct 8, 2024

✅ Docs Preview Ready

No new or changed pages found.

Copy link
Contributor

github-actions bot commented Oct 8, 2024

@SimonSapin, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

Comment on lines 896 to 900
.operation
.selection_set
.selections
.iter()
.all(|sel| sel.as_field().is_some_and(|f| f.name == "__typename"))
Copy link
Member

Choose a reason for hiding this comment

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

this could/should also use operation.root_fields(), i guess, but doesn't need to be addressed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

root_fields() is used to compute doc.has_root_typename and implicitly descends into inline and named fragments regardless of any directive they might have. This specifically only looks at field, in order to not deal with potential @skip or @include that fragments might have.

… but now I realize that fields can also have @skip or @include, so I’ll add this restriction to the condition here.

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’ll simplify this further in the next PR, having a fast path only for literally {__typename} and letting introspection code deal with any other combination of fragments, aliases, directives, etc.

Copy link
Member

Choose a reason for hiding this comment

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

I figured that if we have a fast path for root typename, we might as well have a fast path for something like this?

fragment tyname on Query { __typename }
{
  ... { ...tyname }
}

Though I wonder how useful a __typename fast path is in general with Rust introspection.

Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

LGTM, removing Vec is very nice 🥳

@SimonSapin SimonSapin enabled auto-merge (squash) October 10, 2024 07:13
@SimonSapin SimonSapin merged commit 644d903 into dev Oct 10, 2024
14 checks passed
@SimonSapin SimonSapin deleted the simon/more-query-analysis branch October 10, 2024 07:32
@router-perf
Copy link

router-perf bot commented Oct 11, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

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