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

[typescript-react-apollo] dedupeOperationSuffix doesn't work when operation name is all upper case #126

Open
offirgolan opened this issue May 5, 2021 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@offirgolan
Copy link

offirgolan commented May 5, 2021

Describe the bug

The typescript-react-apollo plugin doesn't properly handle deduping operation suffix when the suffix is all upper case.

To Reproduce

Generate apollo typescript hooks with an operation name that is all caps and post-fixed with QUERY, MUTATION, or FRAGMENT.

  1. My GraphQL schema:
type Query {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String!
}
  1. My GraphQL operations:
query GET_USER_QUERY {
    user(id: 1) {
        id
        username
        email
    }
}
  1. My codegen.yml config file:
config:
  apolloClientVersion: 3
  dedupeOperationSuffix: true
  namingConvention:
    transformUnderscore: true
documents:
  - './src/**/*.graphql'
generates:
  src/graphql/types-and-hooks.ts:
    schema: schema.graphql
    plugins:
      - 'typescript'
      - 'typescript-operations'
      - 'typescript-react-apollo'

Expected behavior

A hook should be generated with pascal case without duplicate operation name suffix

export function useGetUserQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<GetUserQuery, GetUserQueryVariables>) {
        const options = {...defaultOptions, ...baseOptions}
        return ApolloReactHooks.useQuery<GetUserQuery, GetUserQueryVariables>(GetUserQueryDocument, options);
      }

Environment:

  • OS: MacOS 11.3
  • "@graphql-codegen/cli": "^1.21.3",
  • "@graphql-codegen/typescript": "^1.21.1",
  • "@graphql-codegen/typescript-operations": "^1.17.15",
  • "@graphql-codegen/typescript-react-apollo": "^2.2.4",
  • NodeJS: 12

Additional context

From looking at the codebase, I believe that the operation name being tested here should either be a regex match or convert it to test the operation name via pascalCase(name).includes(...).

@Urigo
Copy link
Collaborator

Urigo commented May 12, 2021

Hi @offirgolan and thank you for the report!

Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.

It seems already got into stage 1 thanks to your reproduction! Thank you for that!

Now in order to advance to stage 2 we'll need a failing test, would be great if someone could help progress the issues through the stages.

Thank you and sorry that this comment is not a complete solution (yet).

@dotansimha dotansimha added the help wanted Extra attention is needed label Jun 20, 2021
@dotansimha dotansimha transferred this issue from dotansimha/graphql-code-generator Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants