feat: implement auto-generated SDK with 100% API coverage #208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Auto-Generated SDK Implementation
Overview
This PR introduces a complete auto-generation system for the TypeScript SDK, providing 100% coverage of Plain's GraphQL API with full type safety.
What's New
🤖 Automatic Code Generation
The SDK now auto-generates:
All generated code is fully typed with 0 TypeScript errors.
🎯 Key Features
1. Per-Type Depth Configuration
Configure fragment nesting depth per type instead of globally:
{ "fragmentDefaults": { "maxDepth": 1, "perTypeDepth": { "Customer": 2, "Thread": 2, "User": 2 } } }Benefits:
2. Override Mechanism
Create
.override.gqlfiles that won't be regenerated:Use cases:
3. Enhanced
rawRequestMethodNow accepts typed document nodes:
🔄 Automated Workflow
GitHub Actions workflow runs daily:
📊 Coverage
Usage
Generate SDK Locally
Using Generated Client
Custom Queries with
rawRequestTechnical Implementation
Architecture
Schema Introspection (
scripts/utils/schema-fetcher.ts).graphqlendpointFragment Generation (
scripts/utils/fragment-generator.ts)perTypeDepthconfigurationOperation Generation (
scripts/utils/operation-generator.ts).gqlfiles for all queries/mutationsClient Generation (
scripts/utils/client-generator.ts)VariablesOf<>ResultOf<>Schema Diffing (
scripts/utils/schema-differ.ts)Type Safety Features
ResultOf<typeof Document>to extract exact types from generated operationsError Handling
Breaking Changes
This is a major version (v6.0.0) due to:
CustomerByIdDocument→CustomerDocument)However, the API surface remains largely compatible:
rawRequestenhancementMigration Guide
For users upgrading from v5.x:
Update imports:
No changes needed for:
client.getCustomers(), etc.)New capabilities:
rawRequestwith typed documentssdk-config.jsonDocumentation
Testing
rawRequestFiles Changed
Added
scripts/generate-sdk.ts- Main generation orchestratorscripts/generate-coverage-report.ts- Coverage and changelog generationscripts/utils/- Generation utilities (5 files).github/workflows/auto-update-sdk.yml- Daily automationdocs/CODEGEN.md- Generation system docsdocs/OVERRIDES_GUIDE.md- Override mechanism guidesdk-config.json- Generation configurationsrc/client.generated.ts- Auto-generated client (6000+ lines)src/graphql/fragments/*.gql- 446 fragment filessrc/graphql/queries/*.gql- 145 query filessrc/graphql/mutations/*.gql- 226 mutation filesModified
src/client.ts- EnhancedrawRequestmethodpackage.json- Added generation scriptsbiome.json- Ignore generated files.gitignore- Ignore.sdk/cache directoryREADME.md- Added v6.0.0 documentationGenerated Stats
Next Steps
After merging:
🎉 This PR provides complete, type-safe, auto-updating coverage of Plain's GraphQL API!