Skip to content

RFC: GraphQL LSP with multi-schema support#307

Merged
whatasoda merged 4 commits into
mainfrom
rfc/graphql-lsp-multi-schema
Feb 1, 2026
Merged

RFC: GraphQL LSP with multi-schema support#307
whatasoda merged 4 commits into
mainfrom
rfc/graphql-lsp-multi-schema

Conversation

@whatasoda
Copy link
Copy Markdown
Owner

Summary

  • Add comprehensive RFC for building an independent GraphQL LSP for soda-gql
  • Add supplementary implementation details report

Key design decisions

  • Callback + Tagged Template API: gql.{schemaName}(({ query, fragment }) => query...) — callback required for intermediate module compatibility, tag names encode operation kind
  • Fragment Arguments RFC syntax: Fragment variables declared in GraphQL via spec proposal #1081
  • Metadata chaining: Tagged template results are callable for attaching metadata
  • Hybrid LSP: vscode-languageserver + graphql-language-service interface layer (not server) + SWC parser
  • SWC for TS parsing: Fast AST analysis for always-on LSP

Documents

File Description
docs/rfcs/graphql-lsp-multi-schema.md Main RFC: motivation, API design, LSP architecture, implementation plan
docs/rfcs/graphql-lsp-implementation-details.md Supplementary: LSP protocol requirements, graphql-language-service analysis, extension opportunities

Open questions (to be resolved during implementation)

  • Type inference strategy (TypedDocumentNode vs $infer)
  • Fragment cross-file resolution approach
  • Schema reload strategy

Test plan

  • Review RFC for consistency and completeness
  • Validate code examples match existing soda-gql patterns
  • Confirm Fragment Arguments RFC syntax is correctly described

🤖 Generated with Claude Code

whatasoda and others added 4 commits January 31, 2026 20:56
Comprehensive design document covering:
- Tagged template API design (3 pattern candidates with comparison)
- LSP architecture analysis (graphql-language-service-server vs
  from-scratch vs hybrid approach)
- Multi-schema resolution via import path association
- Implementation plan (5 phases)
- Alternatives considered and open questions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Supplementary document covering:
- LSP protocol requirements by tier (core/navigation/productivity/advanced)
- graphql-language-service interface layer API analysis with function
  signatures
- Components that must be built from scratch (template extractor,
  position mapping, schema management, cross-file fragments, handler
  wiring)
- soda-gql-specific extension opportunities (inlay hints, code lens,
  custom validation rules, semantic tokens, multi-schema context
  indicator, compat migration actions, build integration commands)
- Risk analysis and dependency overview

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Commit to Pattern C (gql.{schemaName} tagged template extension) and
Hybrid LSP architecture (graphql-language-service interface + custom
server). Move rejected alternatives (Patterns A/B, server wrap,
full scratch) to Alternatives Considered with rationale.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rewrite API design to require callback wrapper:
- gql.{schemaName}(({ query, fragment }) => query`...`)
- query/mutation/subscription/fragment as tagged template tags
- Fragment Arguments RFC syntax for fragment variables
- Tagged template results callable for metadata chaining
- SWC for TS AST parsing in LSP
- Fragment Arguments preprocessor for graphql-js compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 1, 2026

Test Coverage Report

Overall Coverage: 79.9% (10821/13537 lines)

Package Coverage Lines
packages/babel 62.9% 502/798
packages/builder 87.4% 3477/3976
packages/cli 87.3% 227/260
packages/codegen 92.1% 2354/2556
packages/colocation-tools 77.0% 235/305
packages/common 82.3% 568/690
packages/config 79.1% 292/369
packages/core 94.6% 1622/1714
packages/formatter 90.8% 297/327
packages/metro-plugin 33.7% 101/300
packages/runtime 100.0% 2/2
packages/sdk 91.7% 66/72
packages/swc 18.1% 76/421
packages/tsc 66.8% 532/796
packages/typegen 80.8% 437/541
packages/webpack-plugin 8.0% 33/410

@whatasoda
Copy link
Copy Markdown
Owner Author

cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@whatasoda whatasoda merged commit 9fc2c24 into main Feb 1, 2026
3 checks passed
@whatasoda whatasoda deleted the rfc/graphql-lsp-multi-schema branch February 1, 2026 04:59
whatasoda added a commit that referenced this pull request Feb 1, 2026
## Summary

- Implement `@soda-gql/lsp` package providing a GraphQL Language Server
Protocol server for soda-gql's tagged template API (RFC #307, Phase 0 +
Phase 1)
- SWC-based template extraction from `gql.{schemaName}(({ query }) =>
query`...`)` callback patterns with multi-schema resolution
- LSP features: diagnostics (validation), completion (field/argument
suggestions), hover (type information)
- Fragment Arguments RFC syntax preprocessing (strips non-standard
syntax before `graphql-language-service` validation)
- Bidirectional TS ↔ GraphQL position mapping for accurate
diagnostic/completion positions
- CLI integration via `soda-gql lsp` command (stdio transport)

### Architecture

| Component | File | Role |
|-----------|------|------|
| Schema resolver | `src/schema-resolver.ts` | Loads/caches GraphQL
schemas from config |
| Document manager | `src/document-manager.ts` | SWC-based tagged
template extraction |
| Fragment preprocessor | `src/fragment-args-preprocessor.ts` | Strips
Fragment Arguments for validation |
| Position mapping | `src/position-mapping.ts` | TS ↔ GraphQL position
conversion |
| Diagnostics | `src/handlers/diagnostics.ts` | Schema validation via
graphql-language-service |
| Completion | `src/handlers/completion.ts` | Field/argument
autocompletion |
| Hover | `src/handlers/hover.ts` | Type information on hover |
| Server | `src/server.ts` | LSP protocol wiring (vscode-languageserver)
|

### Not included (deferred)

- `codegen lsp-config` subcommand (`.graphqlrc.generated.json`
generation) — separate PR
- Phase 2+ features (definition, cross-file fragments, inlay hints)

## Test plan

- [ ] `bun --conditions=@soda-gql test packages/lsp/` — 60 tests pass
- [ ] `bun typecheck` — no LSP-introduced errors (pre-existing
`packages/core` errors only)
- [ ] `bun --conditions=@soda-gql packages/cli/src/index.ts lsp --help`
— prints help
- [ ] Integration tests verify end-to-end flow: document parsing →
diagnostics/completion/hover

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.5 <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