Graphql-code-generator: When using withHooks we seeing a space as `use<queryName>Lazy Query` instead of one word

Created on 18 Aug 2019  路  2Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

The generated code has a space like below.

      export function useTodoStateLazy Query(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<SchemaTypes.ITodoStateQuery, SchemaTypes.ITodoStateQueryVariables>) {
        return ApolloReactHooks.useLazyQuery<SchemaTypes.ITodoStateQuery, SchemaTypes.ITodoStateQueryVariables>(TodoStateDocument, baseOptions);
      };

To Reproduce
Steps to reproduce the behavior:

  1. My codegen.yml config file:
  models.tsx:
    documents: "packages/files-client-state/src/**/*.gql"
    schema: 
      - ./packages/client-state/src/**/*.graphql
      - ./packages-modules/module/server/src/graphql/**/*.graphql
    config:
        namingConvention: keep
        typesPrefix: I
        withMutationFn: true
        withHOC: true
        withComponent: true
        withHooks: true
    preset: "@cdmbase/import-types-preset"
    presetConfig:
      typesPath: "core"
      importTypesNamespace: SchemaTypes

Expected behavior

      export function useTodoStateLazy Query(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<SchemaTypes.ITodoStateQuery, SchemaTypes.ITodoStateQueryVariables>) {
        return ApolloReactHooks.useLazyQuery<SchemaTypes.ITodoStateQuery, SchemaTypes.ITodoStateQueryVariables>(TodoStateDocument, baseOptions);
      };

Environment:

  • OS:
  • @graphql-codegen/...: 1.6.1
  • NodeJS:

Additional context

bug plugins

Most helpful comment

From reading the change-case docs, I think this should be pascalCase instead.

All 2 comments

This is because titleCase from change-case is adding the space here

https://github.com/dotansimha/graphql-code-generator/blob/49a835b2463122bd7be3c8aa5422c2cca45e9549/packages/plugins/typescript/react-apollo/src/visitor.ts#L177

require('change-case').titleCase('LazyQuery') === 'Lazy Query'

From reading the change-case docs, I think this should be pascalCase instead.

Was this page helpful?
0 / 5 - 0 ratings