Update GraphQL Schema
Updates the SDK's GraphQL schema and related types from an API server instance.
Usage
code
/schema-update local # Download from local server /schema-update staging # Download from staging server /schema-update # Will prompt for server choice
Checklist
You MUST use TodoWrite to create a todo for EACH step below. Mark each complete only after verification.
Download Schema
- • Determine server source (from argument or ask user):
localorstaging - • Run schema download from
packages/graphql:- •Local:
pnpm gql:download:local - •Staging:
pnpm gql:download:staging
- •Local:
- • Run
pnpm gql:generate:introspectionto generate GraphQL documents
Update Documents
- • Cross-reference
packages/graphql/schema.graphqlwith existing GQL documents - • Add missing fields to existing fragments
- • Introduce new fragments if necessary
- • If new queries or mutations exist in schema, ask user if they should be added
Check for New Enums
- • Search for new
enumdefinitions inpackages/graphql/schema.graphql - • For each new enum:
- •Add enum definition to
packages/graphql/src/enums.tswith JSDoc comments - •Import the enum type in
packages/graphql/src/graphql.ts - •Add scalar binding in
graphqlconfig (alphabetically ordered)
- •Add enum definition to
- • Note: Do NOT create separate type exports for enums - the enum definition serves as both value and type
Export Input Types
- • Check for new input types in schema
- • Common types (used across multiple queries): export from
packages/graphql/src/inputs.ts - • Query-specific types: colocate with corresponding query files (permits.ts, transactions.ts, swaps.ts, user.ts, reserve.ts, hub.ts, misc.ts)
- • Use pattern:
export type InputName = ReturnType<typeof graphql.scalar<'InputName'>>; - • Exclude fork-related input types unless explicitly needed
- • Ensure scalar bindings exist in
graphql.tsfor all input types
Update URQL Cache Configuration
Update packages/client/src/cache.ts to handle new/removed types:
Keys Section
- • Add new types with
idfield: These should be normalized (cached by id)typescriptNewTypeName: (data: NewTypeName) => data.id,
- • Add ephemeral types (value objects without stable identity): Return
nullto disable normalizationtypescriptNewValueObject: () => null,
- • Remove deleted types: Remove any types that no longer exist in the schema
- • When unsure: If you're uncertain whether it needs normalization, ask the user
Resolvers Section
Add field transformers for enhanced client-side types:
- • DateTime fields: Transform to JavaScript
DateobjectstypescriptTypeName: { dateField: transformToDate, // for non-nullable DateTime nullableDateField: transformToNullableDate, // for nullable DateTime }, - • BigDecimal fields: Transform to
BigDecimalclass instancestypescriptTypeName: { decimalField: transformToBigDecimal, // for non-nullable BigDecimal nullableDecimalField: transformToNullableBigDecimal, // for nullable BigDecimal }, - • BigInt fields: Transform to native BigInt
typescript
TypeName: { bigIntField: transformToBigInt, },
Common Patterns
- •Activity types (
*Activity) typically havetimestamp: DateTime!→ usetransformToDate - •Types with
createdAt: DateTime(nullable) → usetransformToNullableDate - •Types with
createdAt: DateTime!(non-nullable) → usetransformToDate - •Health factor types have nullable
BigDecimalfields → usetransformToNullableBigDecimal
Validate
- • Run
pnpm checkfrompackages/graphqlto verify document integrity - • Run
pnpm buildto ensure TypeScript compilation succeeds - • Run
pnpm test --runto verify tests pass - • Run
pnpm lint:fixto format code
Code Patterns
Enum Definition (enums.ts)
typescript
/**
* Description of what this enum represents.
*/
export enum EnumName {
/**
* Description of this value
*/
VALUE_ONE = 'VALUE_ONE',
/**
* Description of this value
*/
VALUE_TWO = 'VALUE_TWO',
}
Scalar Binding (graphql.ts)
typescript
// Add to imports
import type { ..., EnumName } from './enums';
// Add to scalars config (alphabetically)
scalars: {
...
EnumName: EnumName,
...
}
Input Type Export
typescript
export type InputName = ReturnType<typeof graphql.scalar<'InputName'>>;
Stop Conditions
| Condition | Action |
|---|---|
| Schema download fails | Check if server is running, verify URL |
pnpm check fails | Fix document errors before proceeding |
| Build fails | Fix TypeScript errors |
| Tests fail | Investigate and fix failing tests |
Common Mistakes
- •Creating type exports for enums - Enums are both values and types; don't use
ReturnType<typeof graphql.scalar<'EnumName'>> - •Adding new queries/mutations without being asked - Only update existing documents unless explicitly requested
- •Forgetting scalar bindings - Every input type needs a corresponding entry in
graphql.ts - •Non-alphabetical ordering - Scalar bindings should be alphabetically ordered
- •Missing JSDoc comments - All enums should have documentation
- •Forgetting cache.ts updates - New types need keys configuration; types with DateTime/BigDecimal/BigInt need resolvers
- •Wrong nullable transformer - Use
transformToNullableDate/transformToNullableBigDecimalfor nullable fields, non-nullable variants for required fields - •Missing type imports in cache.ts - Add imports for any new types used in the keys section