feat: implement auto-generated SDK with 100% API coverage#208
feat: implement auto-generated SDK with 100% API coverage#208danperks wants to merge 2 commits intoteam-plain:mainfrom
Conversation
- Add complete code generation system for GraphQL operations - Generate 446 fragments, 145 queries, 226 mutations (371 total methods) - Implement per-type depth configuration for fragment nesting - Add override mechanism (.override.gql files) for custom operations - Enhance rawRequest to accept TypedDocumentNode for type safety - Add GitHub Actions workflow for daily schema updates - Add comprehensive documentation (CODEGEN.md, OVERRIDES_GUIDE.md) - Organize docs into /docs folder - All generated code has 0 TypeScript errors Breaking changes: - Some document names changed (e.g., CustomerByIdDocument -> CustomerDocument) - This is v6.0.0 - see PR_SUMMARY.md for migration guide
|
@danperks is attempting to deploy a commit to the Plain Team on Vercel. A member of the Team first needs to authorize it. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
- CustomerByIdDocument → CustomerDocument - CustomerGroupByIdDocument → CustomerGroupDocument - UserByIdDocument → UserDocument - IndexDocumentDocument → CreateIndexedDocumentDocument - CustomerTenantsDocument → CustomerDocument - Remove duplicate SetCustomerTenantsDocument import All tests now passing (40/40)
|
@danperks hey there! Thanks for your submission! We also explored this option. However, we'd like to first try to do something similar to Linear's SDK which makes resolvers awaitable meaning that you can navigate your graph gradually, vs requesting everything every time which puts us (as the API maintainer) in a tough position when it comes to making changes to it. That's why in the existing SDK we don't select all fields on all resources. |
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!