How It Works
When interacting with the Openlane Core API, most requests use the GraphQL API. Code generation creates TypeScript types from your queries automatically.Workflow
Adding a New Query
Follow these steps to add a new GraphQL query or mutation:1. Create or Update Query File
Add your query to/packages/codegen/query/. Queries should be added to a file relevant to the object(s) being used.
For example, add organization queries to organization.graphql:
2. Run Code Generation
Execute the task command to generate types and hooks:- Runs the
generatecommand to create TypeScript types - Runs a
cleancommand for necessary cleanup on generated files
The clean step fixes import paths for
graphql-request types. See issue #501.Configuration
The codegen behavior is configured ingraphql-codegen.yml:
packages/codegen/graphql-codegen.yml
Key Configuration Options
| Option | Description |
|---|---|
exposeDocument | Adds document field to each query hook for use with queryClient.fetchQuery |
exposeQueryKeys | Adds getKey(variables) function for cache updates |
exposeMutationKeys | Adds getKey() function to mutation hooks |
exposeFetcher | Adds fetcher field for prefetching |
addInfiniteQuery | Generates infinite query variants |
useTypeImports | Uses TypeScript import type syntax |
Scalar Mappings
GraphQL scalars are mapped to TypeScript types:Generated Files
Code generation produces several files:/packages/codegen/src/schema.ts
Contains:
- Base TypeScript types from the GraphQL schema
- Operation types for queries and mutations
- Type-safe variables for each operation
/packages/codegen/src/introspectionschema.json
Introspection data for tooling and IDE support.
/packages/codegen/src/type-names.ts
Generated constants for type names (via custom plugin).
Custom Plugins
The codegen process uses custom plugins to generate additional files:generate-hooks.js
Automatically generates React Query hooks in/apps/console/src/lib/graphql-hooks/:
- Scans query files for GraphQL operations
- Generates typed hooks using React Query
- Adds automatic cache invalidation
- Supports queries, mutations, and bulk operations
Other Plugins
generate-type-constants.js- Creates constant exports for type namesgenerate-queries.js- Additional query utilities
Task Commands
Available tasks inTaskfile.yaml:
Dependencies
Key packages used for code generation:Best Practices
Organize by Domain
Group related queries in files by domain object (e.g.,
user.ts, organization.ts).Regenerate After Schema Changes
Run
task codegen:codegen whenever the GraphQL schema updates.Use Apollo Explorer
Test queries in Apollo GraphQL Explorer before adding them.
Type Safety
Always use the generated TypeScript types for variables and responses.