Skip to content

feat(graphql): GraphQL operations as data sources (7.1, C4)#61

Merged
officialCodeWork merged 1 commit into
developmentfrom
build/phase-7/step-7.1-graphql-adapter
Jul 17, 2026
Merged

feat(graphql): GraphQL operations as data sources (7.1, C4)#61
officialCodeWork merged 1 commit into
developmentfrom
build/phase-7/step-7.1-graphql-adapter

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

Phase 7.1 — GraphQL adapter (failure mode C4) · first Phase 7 step

Recognizes the GraphQL a component runs and treats each operation as a data source, reusing the existing data-source node + fetches-from wiring. No schema changegraphql was already a DataSourceKind.

Changes

  • graphql.ts
    • parseGraphqlOperation — reads operation type/name (and root selection fields as an anonymous-op fallback) from a gql document; ignores # comments; handles shorthand { … }; returns null for fragment-only docs.
    • graphqlOperationFromArg — resolves a hook's first argument to an operation: an inline gql/graphql tagged template, or an identifier followed via getDefinitionNodes() so an imported/co-located gql const resolves cross-file.
  • detectDataSource gains a GraphQL branch before the react-query branch. Apollo/urql reuse useQuery/useMutation, so it only claims the call when the argument is an actual gql document — otherwise it falls through and react-query handles it. Emits sourceKind: "graphql", method = query/mutation/subscription, endpoint = operation name (the value federation/attribution will join on).

Fixture & tests

  • c4-graphql: imported-const useQuery (GetUsers) + useMutation (CreateUser) + inline useSubscription (OnTick) → one graphql source each with the right method and a fetches-from edge.
  • 9 unit tests including the react-query disambiguation (the c5 fixture's URL-queryFn useQuery/useMutation still classify as react-query, zero graphql sources).

Verification

  • pnpm eval326 pass · determinism 1.000 · all metrics 1.000
  • parser-react 160 tests; full suite, typecheck, lint green.

Codegen response types (feeding 5.5) deferred — needs a .graphql/codegen fixture; the operation→data-source spine here is what unblocks federation (7.6). 7.2–7.6 remain sketch-level pending 0.5.0 tester feedback. Tracker updated.

🤖 Generated with Claude Code

Recognize the GraphQL a component runs and treat each operation as a data source,
reusing the existing data-source node + fetches-from wiring (no schema change —
`graphql` was already a DataSourceKind).

- New graphql.ts: parseGraphqlOperation reads operation type/name (+ root fields
  as an anonymous-op fallback) from a gql document; graphqlOperationFromArg
  resolves a hook argument to an operation — inline gql/graphql tagged template,
  or an identifier followed via getDefinitionNodes() so an imported/co-located
  gql const resolves cross-file.
- detectDataSource gains a GraphQL branch before the react-query branch (Apollo/
  urql reuse useQuery/useMutation, so it only claims the call when the argument
  is an actual gql document, else falls through). Emits sourceKind "graphql",
  method = query/mutation/subscription, endpoint = operation name (the value
  federation/attribution join on).
- New fixture c4-graphql (imported-const useQuery/useMutation + inline
  useSubscription); 9 unit tests incl. react-query disambiguation on c5.

eval 326/0/0/0, determinism 1.000, all metrics 1.000; parser-react 160 tests,
typecheck + lint clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit e59b976 into development Jul 17, 2026
1 check passed
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.

2 participants