Skip to content
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

typed-document-node: camelCase exports by default? #6585

Open
A-Shleifman opened this issue Aug 29, 2021 · 6 comments
Open

typed-document-node: camelCase exports by default? #6585

A-Shleifman opened this issue Aug 29, 2021 · 6 comments
Labels
core Related to codegen core/cli help wanted Extra attention is needed kind/enhancement New feature or request waiting-for-answer Waiting for answer from author

Comments

@A-Shleifman
Copy link

First of all, thank you for this amazing plugin!

By default it generates TypedDocumentNodes in PascalCase. While it makes sense for all generated TypeScript types, it probably should be camelCase for nodes as they are values rather than types. For example, typescript-react-apollo generates functions that start with lowercase letters.

There's a config option namingConvention, but setting it to change-case-all#camelCase changes the case of types as well, which is not what we're looking for.

It also looks like omitOperationSuffix property doesn't work. Ideally, I would like to see the following being generated:

export const getUserQuery = ...;
export const deleteUserMutation = ...;

Is there a config property I'm missing?

@dotansimha
Copy link
Owner

Hi! This issue is specific to codegen and not to this repo. I'm moving it.

@dotansimha dotansimha transferred this issue from dotansimha/graphql-typed-document-node Aug 29, 2021
@dotansimha dotansimha added help wanted Extra attention is needed kind/enhancement New feature or request labels Aug 29, 2021
@A-Shleifman A-Shleifman changed the title Should namingConvention be camelCase by default? typed-document-node: camelCase exports by default? Aug 29, 2021
@n1ru4l
Copy link
Collaborator

n1ru4l commented Sep 3, 2021

@A-Shleifman Can you send a PR with failing tests for omitOperationSuffix?

@n1ru4l n1ru4l added the waiting-for-answer Waiting for answer from author label Sep 3, 2021
@A-Shleifman
Copy link
Author

Sorry, @n1ru4l and @dotansimha for not getting back to this for so long. omitOperationSuffix is no longer relevant as useQuery(GetUserDocument) works much better. The other problem is still relevant. I think typed-document-node should generate Documents in camelCase instead of PascalCase as they are variables, not types.

For example:

type GetUserResult = ResultOf<typeof GetUserDocument>;

this looks like we're trying to get typeof Type. I think it should be getUserDocument.

If I try to configure it myself:

overwrite: true
schema: "./schema.gql"
documents: "queries.gql"
generates:
  graphql.tsx:
    plugins:
      - typescript
      - typescript-operations
      - typed-document-node:
          namingConvention: change-case-all#camelCase

Then the generated variable contains incorrect camelCase types, which should stay PascalCase:

export const getUserDocument = {...} as unknown as DocumentNode<getUserQuery, getUserQueryVariables>;

Here's an example with TypeScript complaining in graphql.tsx

@zingerj
Copy link
Contributor

zingerj commented Oct 25, 2022

Somewhat related: is it possible to generate TDNs like GetUserQuery instead of GetUserDocument? I couldn't find a config option for that. Thanks!

@6XGate
Copy link

6XGate commented Oct 26, 2022

It seems there should probably be a new option for namingConvention, called variableNames maybe, to limit its affect to const/var/let exports.

@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
@aradalvand
Copy link
Contributor

aradalvand commented Mar 3, 2024

Disappointing to see this option still doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli help wanted Extra attention is needed kind/enhancement New feature or request waiting-for-answer Waiting for answer from author
Projects
None yet
Development

No branches or pull requests

7 participants