Skip to content

fix(generator): use dynamic root type names in SelectionSets.ts #1364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2025

Conversation

jasonkuhrt
Copy link
Member

@jasonkuhrt jasonkuhrt commented Jul 14, 2025

Fixes #1353

Summary

Fix custom root type names in SelectionSets generator by using dynamic type references instead of hardcoded "Query" and "Mutation".

Problem

When using GraphQL schemas with custom root type names (e.g., QueryRoot instead of Query), the SelectionSets generator was hardcoding Query and Mutation type names in the $Document interface, causing TypeScript compilation errors.

Example problematic schema:

schema {
  query: QueryRoot
  mutation: MutationRoot  
}

type QueryRoot { getString: String }
type MutationRoot { setString(value: String\!): String }

Root Cause

In src/generator/generators/SelectionSets.ts lines 49-50:

// Before (hardcoded type names)
query?: Record<string, Query<${i._$Scalars}>>
mutation?: Record<string, Mutation<${i._$Scalars}>>

Solution

Replace hardcoded type names with dynamic references to actual root type names:

// After (dynamic type names)  
query?: Record<string, ${renderName(config.schema.kindMap.index.Root.query)}<${i._$Scalars}>>
mutation?: Record<string, ${renderName(config.schema.kindMap.index.Root.mutation)}<${i._$Scalars}>>

Replace hardcoded "Query" and "Mutation" type names with dynamic
references to actual root type names from the schema. This allows
schemas with custom root type names (e.g., QueryRoot, MutationRoot)
to work correctly.

Fixes #1353

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@jasonkuhrt jasonkuhrt force-pushed the fix/custom-root-type-names branch from a5ddf5f to 7c2eb0d Compare July 14, 2025 22:19
jasonkuhrt and others added 3 commits July 14, 2025 19:21
Add test case that demonstrates the bug fixed in #1353 where
SelectionSets generator was using hardcoded Query/Mutation type
names instead of dynamic references to actual root type names.

Test verifies:
- Custom root type names (QueryRoot, MutationRoot) work correctly
- Standard Query/Mutation names still work
- Query-only schemas work correctly

This test would fail before the fix and passes after, proving
the bug existed and the fix resolves it.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Extract common generateAndGetDocument helper
- Simplify test schemas to minimal fields
- Remove redundant comments and descriptions
- Reduce file from 100 to 56 lines while maintaining same coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@jasonkuhrt jasonkuhrt merged commit f74bac1 into main Jul 15, 2025
13 of 14 checks passed
@jasonkuhrt jasonkuhrt deleted the fix/custom-root-type-names branch July 15, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated selection-sets.ts uses hardcoded Query and Mutation types
1 participant