You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportconstGqluserDocument=…// should be [g]ql[U]serDocumentexportconstGqldeleteUserDocument=…// should be [g]ql[D]eleteUserDocumentexportconstGqlDeleteUserUppercaseDocument=…// should be [g]qlDeleteUserUppercaseDocumentexporttypeMutationDeleteUserArgs=…// good, as expectedexporttypeQueryUserArgs=…// good, as expected
namingConvention: { typeNames: "keep" }
exportconstgqluserDocument=…// bad, but as expectedexportconstgqldeleteUserDocument=…// bad, but as expectedexportconstgqlDeleteUserUppercaseDocument=…// good, as expectedexporttypeMutationdeleteUserArgs=…// bad, but as expected?exporttypeQueryuserArgs=…// bad, but as expected?
Expected behavior
With namingConvention: { typeNames: "change-case-all#pascalCase" } (default) I expect:
Types start uppercase.
Explicit prefixes and suffixes remain exactly as defined. I chose a lowercase prefix here because these are used for variable names, not type names.
exportconstgqlUserDocument=…// good, as expectedexportconstgqlDeleteUserDocument=…// good, as expectedexportconstgqlDeleteUserUppercaseDocument=…// good, as expectedexporttypeMutationDeleteUserArgs=…// good, as expectedexporttypeQueryUserArgs=…// good, as expected
It's impossible to achieve that consistency easily with the currently available config options. Either the gql prefix starts uppercase or the …Args types are lowercase after Mutation and Query. The only alternative is to write my own conversion function that checks if the string (which can be either a type or a variable name) starts with my prefix and then treat that in a special way.
Also, I need to write all operation names in uppercase in the GraphQL document in order to achieve gqlUserDocument instead of gqluserDocument, which seems odd.
--
This happens because documentVariablePrefix/Suffix are passed as prefix/suffix to the convertName and thus converted as if they're part of the type name. They should instead be applied after converting the type name.
Which packages are impacted by your issue?
@graphql-codegen/visitor-plugin-common
Describe the bug
namingConvention
is supposed to affect type names (typeNames
) and enum value names (enumValues
) only.However, variable names created with
typed-document-node
for operations are also affected by the option, which is not expected.Your Example Website or App
https://stackblitz.com/edit/github-xc1bjj?file=types.ts
Steps to Reproduce the Bug or Issue
In the Stackblitz example, set the
namingConvention
and runnpm run generate
to test the following scenarios:namingConvention: { typeNames: "change-case-all#pascalCase" }
(default)namingConvention: { typeNames: "keep" }
Expected behavior
With
namingConvention: { typeNames: "change-case-all#pascalCase" }
(default) I expect:It's impossible to achieve that consistency easily with the currently available config options. Either the
gql
prefix starts uppercase or the…Args
types are lowercase afterMutation
andQuery
. The only alternative is to write my own conversion function that checks if the string (which can be either a type or a variable name) starts with my prefix and then treat that in a special way.Also, I need to write all operation names in uppercase in the GraphQL document in order to achieve
gqlUserDocument
instead ofgqluserDocument
, which seems odd.--
This happens because
documentVariablePrefix/Suffix
are passed asprefix/suffix
to theconvertName
and thus converted as if they're part of the type name. They should instead be applied after converting the type name.graphql-code-generator/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts
Lines 743 to 749 in 39e6e80
Screenshots or Videos
No response
Platform
graphql
version: 16.8.1, 16.2.0@graphql-codegen/cli
: 5.0.2@graphql-codegen/near-operation-file-preset
: 3.0.0@graphql-codegen/typed-document-node
: 5.0.7@graphql-codegen/typescript
: 4.0.7@graphql-codegen/typescript-operations
: 4.2.1@graphql-typed-document-node/core
: 3.2.0Codegen Config File
Additional context
Schema
Document
The text was updated successfully, but these errors were encountered: