Skip to content

feat: proxy signal/event/segment queries to dq#289

Draft
elffjs wants to merge 5 commits into
mainfrom
feat/proxy-to-dq
Draft

feat: proxy signal/event/segment queries to dq#289
elffjs wants to merge 5 commits into
mainfrom
feat/proxy-to-dq

Conversation

@elffjs
Copy link
Copy Markdown
Member

@elffjs elffjs commented Apr 21, 2026

Summary

  • Adds a new internal/proxy package with a thin GraphQL HTTP client and all query builders/response mappers needed to forward requests to dq
  • Seven resolvers (signals, signalsLatest, availableSignals, dataSummary, events, segments, dailyActivity) check for ProxyClient at the top of each handler and delegate to dq when it's configured
  • vinVCLatest, attestations, and signalsSnapshot keep their existing ClickHouse-backed implementations (phase 2)

Activation: set DQ_ENDPOINT=http://<dq-host>:3000/query in settings. Unset = existing ClickHouse behavior unchanged.

Key transforms applied per request:

  • tokenId (int) → ERC721 DID subject string via existing chain/contract config
  • DetectionMechanism camelCase → UPPER_SNAKE_CASE (dq schema)
  • JWT Authorization header forwarded as-is (same token-exchange issuer)
  • Per-signal SignalFloatFilter/SignalLocationFilter values are passed as named GraphQL variables (not inlined), producing valid GraphQL
  • EventFilter.tags field stripped before forwarding (dq's EventFilter doesn't include it)

Alias handling for signals: aggregationArgsFromContext already captures both the schema field name and the client alias into FloatSignalArgs.Alias. The proxy emits alias: fieldName(agg: AGG) in the dq query, dq returns {"alias": value}, and we key ValueNumbers[alias] — matching how the generated field resolvers look up values.

Test plan

  • All existing tests pass (go test ./...)
  • Start dq locally, set DQ_ENDPOINT, query signals via telemetry-api — verify tokenId→subject conversion and data flows through dq
  • Query segments with ignitionDetection — verify dq receives IGNITION_DETECTION
  • Query signals with a field alias — verify alias is preserved in response
  • Unset DQ_ENDPOINT — verify fallback to ClickHouse still works

🤖 Generated with Claude Code

elffjs and others added 5 commits April 21, 2026 10:19
Adds an optional dq proxy mode. When DQ_ENDPOINT is set, the seven main
query resolvers (signals, signalsLatest, availableSignals, dataSummary,
events, segments, dailyActivity) forward to dq instead of querying
ClickHouse directly.

Key transforms applied per request:
- tokenId → ERC721 DID subject string
- DetectionMechanism camelCase → UPPER_SNAKE_CASE
- JWT Authorization header forwarded as-is (same token issuer)
- Per-signal filters use named GraphQL variables (not inline JSON)

vinVCLatest, attestations, and signalsSnapshot retain their existing
ClickHouse-backed implementations for now.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dq's EventFilter has the same tags field as telemetry-api's, so the
wrapper type stripping it was unnecessary and wrong.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
transform_test.go covers:
- ToSubject, ToDQMechanism (all 6 values + invalid)
- BuildSignalsQuery: no filters, alias preserved, float filter with
  named variables, approximate-coordinates alias mapping, required vars
- UnmarshalSignalsResponse: basic, alias→map key, null skipped, multi-row
- BuildSignalsLatestQuery: field inclusion, lastSeen toggle
- UnmarshalSignalsLatestResponse: happy path, null body

client_test.go covers:
- Execute: auth header forwarding, no-auth, variable serialization,
  GraphQL error propagation, data JSON passthrough
- ProxySignals round-trip: correct subject/interval/query sent, response
  unmarshaled with alias preserved
- ProxySegments: DetectionMechanism mapped to UPPER_SNAKE_CASE

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant