Overview
The@repo/codegen package provides GraphQL code generation using @graphql-codegen. It generates TypeScript types, hooks, and utilities from GraphQL queries and mutations, enabling type-safe interactions with the Openlane Core GraphQL API.
Installation
Key Features
- Auto-generated TypeScript types from GraphQL schema
- Type-safe query and mutation hooks
- GraphQL document nodes for use with GraphQL clients
- Introspection schema for tooling support
- Custom scalar mappings (DateTime, UUID, JSON, etc.)
Architecture
The package usesgraphql-codegen.yml configuration to generate code from:
- Schema Source:
https://raw.githubusercontent.com/theopenlane/core/main/internal/graphapi/clientschema/schema.graphql - Query/Mutation Files:
./query/**/*.ts - Output:
./src/schema.tsand./src/introspectionschema.json
Generated Files
| File | Description |
|---|---|
src/schema.ts | Main export with all types, queries, mutations |
src/type-names.ts | Object type constants and metadata |
src/introspectionschema.json | Schema introspection data |
query/*.ts | GraphQL query/mutation definitions |
Usage
Importing Types
Using Generated Hooks
The package generates hooks for queries and mutations based on your GraphQL documents:Importing Type Constants
Using Enums
Code Generation Workflow
1. Create GraphQL Queries
Add queries/mutations to/query directory. Group by domain (e.g., organization.graphql, user.graphql):
2. Run Code Generation
3. Use Generated Code
Configuration
Scalar Mappings
Custom scalars are mapped to TypeScript types:CodeGen Features
exposeDocument: true- Adds document field to each hookexposeQueryKeys: true- GeneratesgetKey()functions for cache updatesaddInfiniteQuery: true- Generates infinite query hooksexposeMutationKeys: true- Generates mutation keysexposeFetcher: true- Generates fetcher functions
Common Patterns
Filtering and Pagination
Type-safe Mutations
Working with Fragments
Best Practices
- Use Apollo GraphQL Explorer for query development: Apollo Sandbox
- Group queries by domain - Keep related queries in the same file
- Use fragments for reusable field selections
- Run codegen after schema changes - Keep generated types in sync
- Import from schema.ts - All generated types are exported from the main schema file