When using import-types with typescript-urql, the generated document variable will also incorrectly get prefixed. This same behavior also occurs if you set the importOperationTypesFrom config manually with no presets.
import * as Types from './graphql.d'
const UserDocument = ...
export function useUserQuery(options?: Omit<Urql.UseQueryArgs<Types.UserQueryVariables>, 'query'>) {
return Urql.useQuery<Types.UserQuery>({ query: Types.UserDocument, ...options });
};
This greedy prefixing behavior does not occur if you use the near-operation-file preset with baseTypesPath+importTypesNamespace. It actually does the opposite and doesn't prefix anything; you need to use the typesPrefix config. But at least that config does not prefix the document variable.
Issue workflow progress
[x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
[ ] 2. A failing test has been provided
[ ] 3. A local solution has been provided
[ ] 4. A pull request is pending review
Describe the bug
When using
import-types
withtypescript-urql
, the generated document variable will also incorrectly get prefixed. This same behavior also occurs if you set theimportOperationTypesFrom
config manually with no presets.I believe the problem code is here:
https://github.com/dotansimha/graphql-code-generator/blob/cb59afdcea134385e34d544b90e1cd189945230a/packages/plugins/typescript/urql/src/visitor.ts#L145-L147
Sidenote
This greedy prefixing behavior does not occur if you use the
near-operation-file
preset withbaseTypesPath
+importTypesNamespace
. It actually does the opposite and doesn't prefix anything; you need to use thetypesPrefix
config. But at least that config does not prefix the document variable.To Reproduce
My
codegen.yml
config file:Expected behavior
A
Types.
prefix will not be added to the document variable when usingimport-types
Workaround
Use the
add
plugin withtypesPrefix
config instead ofimport-types
preset.Environment: