ardeois / graphql-codegen-typescript-mock-data

[GraphQL Codegen Plugin](https://github.com/dotansimha/graphql-code-generator) for building mock data based on the schema.
MIT License
133 stars 47 forks source link

Wrong generation typeName and mock functions names #40

Closed vitorcamachoo closed 2 years ago

vitorcamachoo commented 3 years ago

Hii,

I'm getting wrong typeNames when reusing types from another generated files and for the functions that are being reused inside mock generated file like you can check in the screenshot: Configuration: Screenshot 2021-02-10 at 11 46 05

Result: Screenshot 2021-02-10 at 11 46 17

ardeois commented 3 years ago

Hi,

It's probably an issue with typenames: pascal-case, can you try without this option? If it doesn't work, can you check if it's due to prefix option as well?

PRs are welcomed to fix this bug, but if you can't, can you provide a unit test or repository to reproduce ?

Thanks

vitorcamachoo commented 3 years ago

I've tried with multiple configurations. The first thing I'm seeing is the top import when I'm trying to reuse types, I have my types on PascalCase and it's importing as lowercase. The order thing is the reuse of the factory functions, for example mockUser (with prefix mock, also the default have the same problem) is defined, but on the rest of the other factories that will use this mockUser it is being written as mockuser as lowercase.

By the way, this plugin will be very helpful to my team 🙌

ardeois commented 3 years ago

@vitorcamachoo I think it's because your typenames config is wrong It should be:

plugins:
      - typescript-mock-data
config:
      typesFile: ./types.ts'
      typenames: 'pascal-case#pascalCase'
      prefix: 'mock'

See documentation

vitorcamachoo commented 3 years ago

Hi @ardeois, with the configuration that you wrote, I get the same errors like you can see on the attached screenshots:

Screenshot 2021-02-11 at 22 10 43 Screenshot 2021-02-11 at 22 10 59 Screenshot 2021-02-11 at 22 11 27

ardeois commented 3 years ago

Could you provide me a repo to reproduce? I tried to reproduce in local and was not able to reproduce.

ccblaisdell commented 3 years ago

I'm getting this same, but so far I'm struggling to create a minimal reproduction. I'll post an update as soon as I can.

ccblaisdell commented 3 years ago

@ardeois A colleague found that the root of this bug is in the graph definition itself

Here's an example with a failing test https://github.com/ardeois/graphql-codegen-typescript-mock-data/compare/master...ccblaisdell:fix-pascalcase-in-mock-dependencies?expand=1

ardeois commented 2 years ago

~Fixed in version 1.5.8~

@vitorcamachoo @ccblaisdell Version 1.6.0 actually really fixes it