Skip to content

feat(graphql): trace Apollo Federation entity resolvers and skip the health-check#9134

Merged
tlhunter merged 7 commits into
masterfrom
BridgeAR/2026-06-29-graphql-federation-union-traversal
Jul 14, 2026
Merged

feat(graphql): trace Apollo Federation entity resolvers and skip the health-check#9134
tlhunter merged 7 commits into
masterfrom
BridgeAR/2026-06-29-graphql-federation-union-traversal

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

Summary

Apollo Federation subgraphs lost resolver tracing in two ways:

  1. The resolver-wrapping traversal only descended through lists and non-nulls, so object types referenced solely as union members or interface implementations were never wrapped. A subgraph's entity types are reachable only through the synthetic _Entity union returned by _entities, so their fields produced no graphql.resolve spans. The walk now descends into union members (getTypes()) and interface implementations (schema.getPossibleTypes()), keyed off the realm-agnostic Symbol.toStringTag discriminator; patchedTypes keeps it one-time per type, so cyclic abstract types terminate and there is no per-resolve cost.

  2. Apollo Gateway polls every subgraph with a fixed __ApolloServiceHealthCheck__ operation, burying real traffic under health-check noise. That operation is now skipped by exact name before span creation, the same built-in treatment mongodb gives its heartbeat command.

Test plan

  • PLUGINS=graphql — federation/abstract-type specs run on graphql 16 (built with the real @apollo/subgraph), the rest unchanged.
  • PLUGINS=apollo — gateway tracing unaffected.

Fixes: #1057

@dd-octo-sts

dd-octo-sts Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.71 MB
Deduped: 7.37 MB
No deduping: 7.37 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-official

datadog-official Bot commented Jun 29, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 96.55% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bdc17a5 | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented Jun 29, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-13 12:13:23

Comparing candidate commit bdc17a5 in PR branch BridgeAR/2026-06-29-graphql-federation-union-traversal with baseline commit adf5f1c in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2326 metrics, 32 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-209.671ms; +214.076ms] or [-7.896%; +8.062%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-234.705ms; +229.119ms] or [-9.206%; +8.987%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-190.208ms; +186.823ms] or [-6.546%; +6.429%]

scenario:appsec-control-20

  • unstable execution_time [-125.581ms; +131.337ms] or [-7.617%; +7.967%]

scenario:appsec-control-24

  • unstable execution_time [-115.990ms; +112.055ms] or [-9.346%; +9.029%]

scenario:appsec-control-26

  • unstable execution_time [-121612.305µs; +120207.538µs] or [-9.858%; +9.744%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-19.216ms; +8.727ms] or [-7.433%; +3.376%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-9.520ms; +17.273ms] or [-3.724%; +6.757%]

scenario:appsec-iast-with-vulnerability-control-20

  • unstable execution_time [-29.266ms; +32.317ms] or [-5.298%; +5.850%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-30.975ms; +34.680ms] or [-5.631%; +6.305%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable instructions [-4.5G instructions; +2.1G instructions] or [-6.838%; +3.235%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-2.448s; +0.415s] or [-27.717%; +4.703%]
  • unstable execution_time [-2.464s; +0.412s] or [-25.831%; +4.318%]
  • unstable instructions [-20.9G instructions; +3.5G instructions] or [-28.836%; +4.888%]
  • unstable throughput [-131.263op/s; +677.344op/s] or [-3.751%; +19.355%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-1786.702ms; +598.291ms] or [-19.084%; +6.390%]
  • unstable execution_time [-1822.675ms; +598.119ms] or [-18.083%; +5.934%]
  • unstable instructions [-16.1G instructions; +5.2G instructions] or [-20.552%; +6.625%]
  • unstable throughput [-132.842op/s; +397.917op/s] or [-4.080%; +12.221%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-1800.676ms; +3690.305ms] or [-20.538%; +42.091%]
  • unstable execution_time [-1801.879ms; +3699.952ms] or [-18.981%; +38.976%]
  • unstable instructions [-16.1G instructions; +38.7G instructions] or [-22.144%; +53.199%]
  • unstable max_rss_usage [-7.404MB; +15.682MB] or [-4.673%; +9.897%]
  • unstable throughput [-1044.411op/s; +519.817op/s] or [-29.844%; +14.854%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-358.627ms; +272.647ms] or [-7.080%; +5.383%]
  • unstable execution_time [-356.380ms; +275.161ms] or [-6.935%; +5.354%]
  • unstable throughput [-95684.297op/s; +120514.697op/s] or [-5.866%; +7.388%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-700.431ms; +738.036ms] or [-5.455%; +5.747%]
  • unstable execution_time [-698.206ms; +743.933ms] or [-5.318%; +5.667%]
  • unstable throughput [-3.407op/s; +3.204op/s] or [-5.558%; +5.227%]

scenario:plugin-pg-service-24

  • unstable execution_time [-74.496ms; +115.846ms] or [-4.456%; +6.929%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-3.950MB; +5.976MB] or [-4.932%; +7.461%]

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.58%. Comparing base (adf5f1c) to head (bdc17a5).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #9134    +/-   ##
========================================
  Coverage   96.58%   96.58%            
========================================
  Files         918      918            
  Lines      121584   121705   +121     
  Branches    21169    20726   -443     
========================================
+ Hits       117436   117554   +118     
- Misses       4148     4151     +3     
Flag Coverage Δ
aiguard 53.56% <ø> (-0.05%) ⬇️
aiguard-integration 57.01% <ø> (ø)
apm-bucket-0 53.79% <ø> (-0.05%) ⬇️
apm-bucket-1 58.08% <ø> (-0.05%) ⬇️
apm-bucket-2 56.11% <ø> (-0.05%) ⬇️
apm-capabilities-tracing 60.30% <29.41%> (-0.05%) ⬇️
apm-integrations-aerospike 52.94% <ø> (-0.05%) ⬇️
apm-integrations-confluentinc-kafka-javascript 57.06% <ø> (-0.05%) ⬇️
apm-integrations-couchbase 53.28% <ø> (-0.04%) ⬇️
apm-integrations-http 57.96% <ø> (-0.05%) ⬇️
apm-integrations-kafkajs 57.71% <ø> (-0.05%) ⬇️
apm-integrations-next 54.24% <ø> (-0.05%) ⬇️
apm-integrations-prisma 54.17% <ø> (-0.05%) ⬇️
apm-integrations-tedious 53.04% <ø> (-0.05%) ⬇️
appsec 69.00% <ø> (-0.04%) ⬇️
appsec-express_fastify_graphql 65.62% <73.52%> (-0.02%) ⬇️
appsec-integration 45.64% <73.52%> (+0.04%) ⬆️
appsec-kafka_ldapjs_lodash 59.09% <ø> (-0.04%) ⬇️
appsec-mongodb-core_mongoose_mysql 62.25% <ø> (-0.04%) ⬇️
appsec-next 52.85% <ø> (-0.04%) ⬇️
appsec-node-serialize_passport_postgres 61.88% <ø> (-0.04%) ⬇️
appsec-sourcing_stripe_template 60.34% <ø> (-0.04%) ⬇️
debugger 65.73% <ø> (ø)
instrumentations-bucket-0 48.75% <ø> (-0.05%) ⬇️
instrumentations-bucket-1 54.96% <ø> (-0.05%) ⬇️
instrumentations-bucket-10 56.63% <ø> (-0.05%) ⬇️
instrumentations-bucket-11 48.74% <ø> (-0.05%) ⬇️
instrumentations-bucket-12 48.84% <ø> (-0.05%) ⬇️
instrumentations-bucket-13 48.68% <ø> (-0.05%) ⬇️
instrumentations-bucket-2 49.74% <ø> (-0.05%) ⬇️
instrumentations-bucket-3 53.83% <ø> (-0.05%) ⬇️
instrumentations-bucket-4 49.16% <ø> (-0.05%) ⬇️
instrumentations-bucket-5 53.01% <ø> (-0.05%) ⬇️
instrumentations-bucket-6 55.60% <ø> (-0.05%) ⬇️
instrumentations-bucket-7 53.61% <ø> (-0.05%) ⬇️
instrumentations-bucket-8 54.64% <ø> (-0.05%) ⬇️
instrumentations-bucket-9 56.10% <ø> (-0.04%) ⬇️
instrumentations-instrumentation-couchbase 48.18% <ø> (-0.05%) ⬇️
instrumentations-integration-esbuild 33.96% <ø> (ø)
llmobs-ai_anthropic_bedrock 57.73% <ø> (-0.04%) ⬇️
llmobs-bucket-1 56.80% <ø> (-0.04%) ⬇️
llmobs-openai 57.56% <ø> (-0.04%) ⬇️
llmobs-sdk 59.95% <ø> (-0.06%) ⬇️
llmobs-vertex-ai 54.21% <ø> (-0.05%) ⬇️
master-coverage 96.58% <100.00%> (?)
openfeature 54.62% <ø> (ø)
openfeature-unit 49.83% <ø> (-0.05%) ⬇️
platform-core_esbuild_instrumentations-misc 38.46% <ø> (-0.03%) ⬇️
platform-integration 62.24% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 37.29% <ø> (-0.03%) ⬇️
plugins-bucket-0 53.18% <ø> (-0.05%) ⬇️
plugins-bucket-1 55.09% <ø> (ø)
plugins-bucket-11 55.64% <73.52%> (+<0.01%) ⬆️
plugins-bucket-18 57.00% <29.41%> (-0.12%) ⬇️
plugins-bucket-19 55.38% <ø> (-0.05%) ⬇️
plugins-bucket-20 57.57% <100.00%> (+0.08%) ⬆️
plugins-bucket-4 53.85% <ø> (-0.05%) ⬇️
plugins-bullmq_cassandra_cookie 57.39% <ø> (-0.05%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 52.32% <ø> (-0.05%) ⬇️
plugins-fetch_fs_generic-pool 54.46% <ø> (-0.05%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 59.87% <ø> (-0.05%) ⬇️
plugins-hapi_hono_ioredis 55.86% <ø> (-0.05%) ⬇️
plugins-jest_knex_langgraph 51.67% <ø> (-0.05%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 53.42% <ø> (-0.05%) ⬇️
plugins-lodash_mariadb_memcached 54.21% <ø> (-0.05%) ⬇️
plugins-moleculer_mongodb_mongodb-core 57.29% <ø> (-0.05%) ⬇️
plugins-mongoose_multer_mysql 54.71% <ø> (-0.05%) ⬇️
plugins-mysql2_nats_node-serialize 56.21% <ø> (-0.05%) ⬇️
plugins-opensearch_passport-http_pino 55.05% <ø> (-0.05%) ⬇️
plugins-postgres_process_pug 54.29% <ø> (-0.05%) ⬇️
plugins-redis_router_sequelize 57.03% <ø> (-0.03%) ⬇️
plugins-test-and-upstream-rhea_undici_url 57.01% <ø> (-0.07%) ⬇️
plugins-valkey_vm_winston 53.93% <ø> (-0.05%) ⬇️
plugins-ws 54.80% <ø> (-0.05%) ⬇️
profiling 58.20% <ø> (-0.05%) ⬇️
serverless-aws-sdk-aws-sdk 50.67% <ø> (-0.04%) ⬇️
serverless-aws-sdk-bedrockruntime 50.69% <ø> (-0.05%) ⬇️
serverless-aws-sdk-client 51.97% <ø> (-0.05%) ⬇️
serverless-aws-sdk-dynamodb 51.78% <ø> (-0.02%) ⬇️
serverless-aws-sdk-eventbridge 46.25% <ø> (-0.05%) ⬇️
serverless-aws-sdk-kinesis 54.71% <ø> (-0.05%) ⬇️
serverless-aws-sdk-lambda 52.79% <ø> (-0.05%) ⬇️
serverless-aws-sdk-s3 51.53% <ø> (-0.05%) ⬇️
serverless-aws-sdk-serverless-peer-service 54.73% <ø> (-0.05%) ⬇️
serverless-aws-sdk-sns 55.48% <ø> (-0.05%) ⬇️
serverless-aws-sdk-sqs 55.91% <ø> (-0.05%) ⬇️
serverless-aws-sdk-stepfunctions 51.25% <ø> (-0.05%) ⬇️
serverless-aws-sdk-util 48.48% <ø> (-0.05%) ⬇️
serverless-bucket-0 55.23% <ø> (-0.01%) ⬇️
serverless-bucket-1 56.01% <ø> (-0.05%) ⬇️
test-optimization-cucumber 72.95% <ø> (+0.04%) ⬆️
test-optimization-cypress 66.33% <ø> (+0.04%) ⬆️
test-optimization-jest 74.26% <ø> (-0.03%) ⬇️
test-optimization-mocha 74.71% <ø> (+0.06%) ⬆️
test-optimization-playwright-playwright-atr 61.57% <ø> (+0.02%) ⬆️
test-optimization-playwright-playwright-efd 61.76% <ø> (+0.03%) ⬆️
test-optimization-playwright-playwright-final-status 61.72% <ø> (+0.02%) ⬆️
test-optimization-playwright-playwright-impacted-tests 61.44% <ø> (+0.19%) ⬆️
test-optimization-playwright-playwright-reporting 61.34% <ø> (+0.02%) ⬆️
test-optimization-playwright-playwright-test-management 62.25% <ø> (-0.09%) ⬇️
test-optimization-playwright-playwright-test-span 61.49% <ø> (-0.03%) ⬇️
test-optimization-selenium 60.67% <ø> (-0.08%) ⬇️
test-optimization-testopt 59.15% <ø> (+0.08%) ⬆️
test-optimization-vitest 71.50% <29.41%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-06-29-graphql-federation-union-traversal branch 3 times, most recently from 02c0b3c to 6e15f5a Compare July 1, 2026 15:51
@BridgeAR
BridgeAR marked this pull request as ready for review July 1, 2026 23:57
@BridgeAR
BridgeAR requested a review from a team as a code owner July 1, 2026 23:57
@BridgeAR
BridgeAR requested review from tlhunter and removed request for a team July 1, 2026 23:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e15f5a698

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/datadog-plugin-graphql/src/execute.js Outdated
Comment thread packages/datadog-plugin-graphql/src/execute.js Outdated
@BridgeAR
BridgeAR marked this pull request as draft July 2, 2026 00:04
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-06-29-graphql-federation-union-traversal branch 2 times, most recently from 9e9429c to 9f56422 Compare July 7, 2026 13:43
@BridgeAR
BridgeAR marked this pull request as ready for review July 7, 2026 14:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f5642226c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/datadog-plugin-graphql/src/execute.js Outdated
@BridgeAR BridgeAR changed the title fix(graphql): trace Apollo Federation entity resolvers and skip the health-check feat(graphql): trace Apollo Federation entity resolvers and skip the health-check Jul 8, 2026

@crysmags crysmags left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no blockers from me. The shape-gated health-check skip and per-schema abstract traversal look right.

I left two small non-blocking comments: one to make the cached-document health-check matcher fully exact, and one to make the "no graphql spans" test assert execute/resolve too.

Comment thread packages/datadog-plugin-graphql/src/utils.js
Comment thread packages/datadog-plugin-graphql/test/index.spec.js
BridgeAR added 6 commits July 10, 2026 20:33
The resolver-wrapping traversal only descended through lists and non-nulls, so
it never reached object types referenced solely as union members or interface
implementations. graphql resolves the concrete type at runtime, so an Apollo
Federation subgraph (whose entity types are reachable only through the synthetic
`_Entity` union returned by `_entities`) produced no graphql.resolve spans for
those fields.

Descend into union members via getTypes() and interface implementations via
schema.getPossibleTypes(), keyed off the realm-agnostic `Symbol.toStringTag`
discriminator so an interface without an explicit resolveType is still covered.
patchedTypes keeps the walk one-time per type, so cyclic abstract types
terminate and there is no per-resolve cost.

Fixes: #1057
Apollo Gateway's polling subgraph health check sends a fixed
`query __ApolloServiceHealthCheck__ { __typename }` on every poll interval,
burying real traffic under health-check noise. Skip that named operation by
exact name before span creation. The skip is unconditional because the name is
spec-reserved (the `__` prefix) and the operation carries no user input, so
there is nothing for AppSec or IAST to inspect and no legitimate operation to
collide with. The gateway's other probe, the anonymous startup
`{ __typename }` query, is left alone on purpose: it fires only on startup and
schema update, so it is not a source of recurring noise.

Fixes: #1057
1. The health-check skip matched the reserved operation name alone. Since
   operation names are client-controlled, a request naming itself
   `__ApolloServiceHealthCheck__` while selecting a real field (or using a
   mutation, or adding selections beside `__typename`) was silently dropped
   from tracing and from the AppSec/IAST resolver channels. Confirm the
   gateway's exact spec-fixed shape (`query __ApolloServiceHealthCheck__
   { __typename }`) before skipping so the reserved name can't become a
   tracing/security bypass.
2. `getPossibleTypes` is schema-specific, but the interface-implementation
   descent shared the global `patchedTypes` guard. Two schemas reusing one
   interface instance meant the first schema's walk marked the interface and
   the second schema's implementations were never wrapped, so their resolvers
   went untraced. Key the interface descent per (schema, interface) instead.
The resolver-wrapping walk terminated on a global per-type guard, but the
walk is schema-dependent: union members and interface implementations are
read through the schema (getTypes / getPossibleTypes) and differ between
schemas. Two schemas sharing any type on the path to an abstract type — a
reused root Query, a shared interface — meant the first schema's walk marked
that type, and the second schema's walk returned at it before reaching its
own members or implementations, leaving those resolvers untraced.

Key the walk's visited set per (schema, type) so each schema runs its own
full traversal. Resolver wrapping is already idempotent via patchedResolvers,
so re-walking a type shared across schemas never double-wraps a resolver.

Fixes: #1057
The health-check skip only suppressed the execute and resolver spans, so a
gateway poll still emitted graphql.parse and graphql.validate. graphql runs
both before execute, so every cold poll (and every poll on servers without a
document cache, e.g. graphql-yoga) left two heartbeat spans a customer's
operation filter would flag.

Detect the poll from the raw query string at parse — the only input parse has —
and mark the produced document so validate and execute skip it too. Apollo
Server caches parsed+validated documents in its documentStore and reuses the
same document object across polls, so a warm poll reaches execute with the
already-marked document; when a health-check document reaches execute without
ever passing through the instrumented parse (pre-populated cache, hand-built
document), the operation-shape check remains the backstop.

Fixes: #1057
Health-check operation names and parsed documents are caller-controlled. Requiring Apollo's complete constant shape keeps transformed or multi-operation documents, and operations with variables or directives, on the traced AppSec and IAST path.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-06-29-graphql-federation-union-traversal branch from dda97b2 to 2c8dab4 Compare July 10, 2026 20:07

@crysmags crysmags left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking question: should the Apollo health-check skip also cover the Mercurius graphql.request span? GraphQLRequestPlugin starts that span before parse/validate/execute run, so the new skips still leave one top-level request span per gateway poll for Mercurius subgraphs. If the goal is only graphql-js/Apollo spans then this is fine, but if we want the health-check to disappear across GraphQL drivers, request.js probably needs the same early guard too.

@tlhunter
tlhunter merged commit c5edb32 into master Jul 14, 2026
657 checks passed
@tlhunter
tlhunter deleted the BridgeAR/2026-06-29-graphql-federation-union-traversal branch July 14, 2026 17:24
This was referenced Jul 15, 2026
juan-fernandez pushed a commit that referenced this pull request Jul 16, 2026
…health-check (#9134)

* fix(graphql): trace resolvers reached through unions and interfaces

The resolver-wrapping traversal only descended through lists and non-nulls, so
it never reached object types referenced solely as union members or interface
implementations. graphql resolves the concrete type at runtime, so an Apollo
Federation subgraph (whose entity types are reachable only through the synthetic
`_Entity` union returned by `_entities`) produced no graphql.resolve spans for
those fields.

Descend into union members via getTypes() and interface implementations via
schema.getPossibleTypes(), keyed off the realm-agnostic `Symbol.toStringTag`
discriminator so an interface without an explicit resolveType is still covered.
patchedTypes keeps the walk one-time per type, so cyclic abstract types
terminate and there is no per-resolve cost.

Fixes: #1057

* fix(graphql): skip the Apollo Federation health-check operation

Apollo Gateway's polling subgraph health check sends a fixed
`query __ApolloServiceHealthCheck__ { __typename }` on every poll interval,
burying real traffic under health-check noise. Skip that named operation by
exact name before span creation. The skip is unconditional because the name is
spec-reserved (the `__` prefix) and the operation carries no user input, so
there is nothing for AppSec or IAST to inspect and no legitimate operation to
collide with. The gateway's other probe, the anonymous startup
`{ __typename }` query, is left alone on purpose: it fires only on startup and
schema update, so it is not a source of recurring noise.

Fixes: #1057

* fix(graphql): harden federation health-check skip and interface walk

1. The health-check skip matched the reserved operation name alone. Since
   operation names are client-controlled, a request naming itself
   `__ApolloServiceHealthCheck__` while selecting a real field (or using a
   mutation, or adding selections beside `__typename`) was silently dropped
   from tracing and from the AppSec/IAST resolver channels. Confirm the
   gateway's exact spec-fixed shape (`query __ApolloServiceHealthCheck__
   { __typename }`) before skipping so the reserved name can't become a
   tracing/security bypass.
2. `getPossibleTypes` is schema-specific, but the interface-implementation
   descent shared the global `patchedTypes` guard. Two schemas reusing one
   interface instance meant the first schema's walk marked the interface and
   the second schema's implementations were never wrapped, so their resolvers
   went untraced. Key the interface descent per (schema, interface) instead.

* fix(graphql): wrap resolvers per schema when types are shared

The resolver-wrapping walk terminated on a global per-type guard, but the
walk is schema-dependent: union members and interface implementations are
read through the schema (getTypes / getPossibleTypes) and differ between
schemas. Two schemas sharing any type on the path to an abstract type — a
reused root Query, a shared interface — meant the first schema's walk marked
that type, and the second schema's walk returned at it before reaching its
own members or implementations, leaving those resolvers untraced.

Key the walk's visited set per (schema, type) so each schema runs its own
full traversal. Resolver wrapping is already idempotent via patchedResolvers,
so re-walking a type shared across schemas never double-wraps a resolver.

Fixes: #1057

* fix(graphql): skip parse and validate spans for the health-check

The health-check skip only suppressed the execute and resolver spans, so a
gateway poll still emitted graphql.parse and graphql.validate. graphql runs
both before execute, so every cold poll (and every poll on servers without a
document cache, e.g. graphql-yoga) left two heartbeat spans a customer's
operation filter would flag.

Detect the poll from the raw query string at parse — the only input parse has —
and mark the produced document so validate and execute skip it too. Apollo
Server caches parsed+validated documents in its documentStore and reuses the
same document object across polls, so a warm poll reaches execute with the
already-marked document; when a health-check document reaches execute without
ever passing through the instrumented parse (pre-populated cache, hand-built
document), the operation-shape check remains the backstop.

Fixes: #1057

* fix(graphql): require exact Apollo health-check documents

Health-check operation names and parsed documents are caller-controlled. Requiring Apollo's complete constant shape keeps transformed or multi-operation documents, and operations with variables or directives, on the traced AppSec and IAST path.
juan-fernandez pushed a commit that referenced this pull request Jul 16, 2026
…health-check (#9134)

* fix(graphql): trace resolvers reached through unions and interfaces

The resolver-wrapping traversal only descended through lists and non-nulls, so
it never reached object types referenced solely as union members or interface
implementations. graphql resolves the concrete type at runtime, so an Apollo
Federation subgraph (whose entity types are reachable only through the synthetic
`_Entity` union returned by `_entities`) produced no graphql.resolve spans for
those fields.

Descend into union members via getTypes() and interface implementations via
schema.getPossibleTypes(), keyed off the realm-agnostic `Symbol.toStringTag`
discriminator so an interface without an explicit resolveType is still covered.
patchedTypes keeps the walk one-time per type, so cyclic abstract types
terminate and there is no per-resolve cost.

Fixes: #1057

* fix(graphql): skip the Apollo Federation health-check operation

Apollo Gateway's polling subgraph health check sends a fixed
`query __ApolloServiceHealthCheck__ { __typename }` on every poll interval,
burying real traffic under health-check noise. Skip that named operation by
exact name before span creation. The skip is unconditional because the name is
spec-reserved (the `__` prefix) and the operation carries no user input, so
there is nothing for AppSec or IAST to inspect and no legitimate operation to
collide with. The gateway's other probe, the anonymous startup
`{ __typename }` query, is left alone on purpose: it fires only on startup and
schema update, so it is not a source of recurring noise.

Fixes: #1057

* fix(graphql): harden federation health-check skip and interface walk

1. The health-check skip matched the reserved operation name alone. Since
   operation names are client-controlled, a request naming itself
   `__ApolloServiceHealthCheck__` while selecting a real field (or using a
   mutation, or adding selections beside `__typename`) was silently dropped
   from tracing and from the AppSec/IAST resolver channels. Confirm the
   gateway's exact spec-fixed shape (`query __ApolloServiceHealthCheck__
   { __typename }`) before skipping so the reserved name can't become a
   tracing/security bypass.
2. `getPossibleTypes` is schema-specific, but the interface-implementation
   descent shared the global `patchedTypes` guard. Two schemas reusing one
   interface instance meant the first schema's walk marked the interface and
   the second schema's implementations were never wrapped, so their resolvers
   went untraced. Key the interface descent per (schema, interface) instead.

* fix(graphql): wrap resolvers per schema when types are shared

The resolver-wrapping walk terminated on a global per-type guard, but the
walk is schema-dependent: union members and interface implementations are
read through the schema (getTypes / getPossibleTypes) and differ between
schemas. Two schemas sharing any type on the path to an abstract type — a
reused root Query, a shared interface — meant the first schema's walk marked
that type, and the second schema's walk returned at it before reaching its
own members or implementations, leaving those resolvers untraced.

Key the walk's visited set per (schema, type) so each schema runs its own
full traversal. Resolver wrapping is already idempotent via patchedResolvers,
so re-walking a type shared across schemas never double-wraps a resolver.

Fixes: #1057

* fix(graphql): skip parse and validate spans for the health-check

The health-check skip only suppressed the execute and resolver spans, so a
gateway poll still emitted graphql.parse and graphql.validate. graphql runs
both before execute, so every cold poll (and every poll on servers without a
document cache, e.g. graphql-yoga) left two heartbeat spans a customer's
operation filter would flag.

Detect the poll from the raw query string at parse — the only input parse has —
and mark the produced document so validate and execute skip it too. Apollo
Server caches parsed+validated documents in its documentStore and reuses the
same document object across polls, so a warm poll reaches execute with the
already-marked document; when a health-check document reaches execute without
ever passing through the instrumented parse (pre-populated cache, hand-built
document), the operation-shape check remains the backstop.

Fixes: #1057

* fix(graphql): require exact Apollo health-check documents

Health-check operation names and parsed documents are caller-controlled. Requiring Apollo's complete constant shape keeps transformed or multi-operation documents, and operations with variables or directives, on the traced AppSec and IAST path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Apollo Gateway / Federation

3 participants