Repository navigation
Conversation
…her imported as type with useTypeImports Skill: oss:issue-verify Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
🦋 Changeset detectedLatest commit: 88850cd The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…/graphql-code-generator#10501) Skill: oss:issue-fix Approved-by: eddeee888 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
| expect(out.prepend).toContain(`import { customFetcher } from './my-file';`); | ||
| }); | ||
|
|
||
| it('Should import the custom fetcher as a value when useTypeImports is true', async () => { | ||
| const config = { | ||
| fetcher: { | ||
| func: '../fetcher#fetcher', | ||
| }, | ||
| useTypeImports: true, | ||
| }; | ||
|
|
||
| const out = (await plugin(schema, docs, config)) as Types.ComplexPluginOutput; | ||
|
|
||
| expect(out.prepend).toContain(`import { fetcher } from '../fetcher';`); | ||
| expect(out.prepend).not.toContain(`import type { fetcher }`); |
There was a problem hiding this comment.
Suggestion: The new test is the same case as the updated Should support useTypeImports test above: it uses a custom named fetcher with useTypeImports: true and expects a value import. Fold the negative assertion into the existing test and drop the duplicate, which also keeps react-query and solid-query in step.
| expect(out.prepend).toContain(`import { customFetcher } from './my-file';`); | |
| }); | |
| it('Should import the custom fetcher as a value when useTypeImports is true', async () => { | |
| const config = { | |
| fetcher: { | |
| func: '../fetcher#fetcher', | |
| }, | |
| useTypeImports: true, | |
| }; | |
| const out = (await plugin(schema, docs, config)) as Types.ComplexPluginOutput; | |
| expect(out.prepend).toContain(`import { fetcher } from '../fetcher';`); | |
| expect(out.prepend).not.toContain(`import type { fetcher }`); | |
| expect(out.prepend).toContain(`import { customFetcher } from './my-file';`); | |
| expect(out.prepend).not.toContain(`import type { customFetcher }`); |
Skill: cops:pr-review
Generated by Claude Code
There was a problem hiding this comment.
Done in 0dd4f52: the negative assertion is folded into Should support useTypeImports in both specs and the duplicate test is gone. f4ee64c makes it check out.prepend.join('\n'), since out.prepend is a string[] and not.toContain on the array never matched a substring.
Skill: cops:pr-address
Generated by Claude Code
| }, | ||
| ], | ||
| this.visitor.config.useTypeImports, | ||
| false, |
There was a problem hiding this comment.
Test: Hard-coding false also changes the default-export branch, and no test covers it. With func: './my-file#default as customFetcher' and useTypeImports: true, the output used to be import type { default as customFetcher } from './my-file'; and is now import customFetcher from './my-file';. Add this case to both the react-query and solid-query specs.
Skill: cops:pr-review
Generated by Claude Code
There was a problem hiding this comment.
Done in 0fab3c8: both specs now cover ./my-file#default as customFetcher with useTypeImports: true, expecting import customFetcher from './my-file';. 88850cd narrows its negative check to import type { default as customFetcher }, because the output also has an unrelated import type { DocumentTypeDecoration }.
Skill: cops:pr-address
Generated by Claude Code
Skill: cops:pr-address Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
Skill: cops:pr-address Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
Skill: cops:pr-address Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
Skill: cops:pr-address Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
| }, | ||
| ], | ||
| this.visitor.config.useTypeImports, | ||
| false, |
There was a problem hiding this comment.
Note: This false is the useTypeImports argument of buildMapperImport. It's hard-coded instead of reading this.visitor.config.useTypeImports because the generated hooks call the custom fetcher at runtime, so it must always be a value import. With useTypeImports: true, the generated imports are import { customFetcher } from './my-file'; and import customFetcher from './my-file'; (default export). The fix lives here rather than in buildMapperImport in visitor-plugin-common, as the issue suggested, because that helper also builds imports for type-only mappers, which should still respect useTypeImports. solid-query/src/fetcher-custom-mapper.ts:42 makes the same change.
Skill: cops:pr-note
Generated by Claude Code
Description
Why: with
useTypeImports: true, a customfetcheris emitted asimport type { fetcher }, andimport typeerases the runtime function the generated hooks call. The reporter hit this underverbatimModuleSyntax, where turninguseTypeImportsoff isn't an option (issue).What: a custom
fetcheris now always imported as a value, named or default, even withuseTypeImports: true, in bothtypescript-react-queryandtypescript-solid-query.Related dotansimha/graphql-code-generator#10501 (filed in the main repo; the plugins live here).
Type of change
How Has This Been Tested?
https://claude.ai/code/session_01NyYayEjLbe5zuHZmgACL3j
Generated by Claude Code