Skip to content

[typescript-react-query, typescript-solid-query] fix: import custom fetcher as a value with useTypeImports (dotansimha/graphql-code-generator#10501) - #1750

Draft
eddeee888 wants to merge 6 commits into
mainfrom
repro/10501
Draft

eddeee888 wants to merge 6 commits into
mainfrom
repro/10501

Conversation

@eddeee888

@eddeee888 eddeee888 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Why: with useTypeImports: true, a custom fetcher is emitted as import type { fetcher }, and import type erases the runtime function the generated hooks call. The reporter hit this under verbatimModuleSyntax, where turning useTypeImports off isn't an option (issue).

What: a custom fetcher is now always imported as a value, named or default, even with useTypeImports: true, in both typescript-react-query and typescript-solid-query.

Related dotansimha/graphql-code-generator#10501 (filed in the main repo; the plugins live here).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests

https://claude.ai/code/session_01NyYayEjLbe5zuHZmgACL3j


Generated by Claude Code

…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-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 88850cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/typescript-react-query Patch
@graphql-codegen/typescript-solid-query Patch

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
Comment on lines +197 to +211
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 }`);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@eddeee888 eddeee888 self-assigned this Nov 27, 2026
Skill: cops:pr-address
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyYayCgJz8KYFTH4LogXLD
@eddeee888 eddeee888 changed the title [typescript-react-query] test: reproduce custom fetcher imported as type with useTypeImports (failing) (dotansimha/graphql-code-generator#10501) [typescript-react-query, typescript-solid-query] fix: import custom fetcher as a value with useTypeImports (dotansimha/graphql-code-generator#10501) Nov 27, 2026
},
],
this.visitor.config.useTypeImports,
false,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

2 participants