I don't know which version this is introduced in but today i upgraded(both codegen and template) from version ^0.9.0 to ^0.12.0 and every type or fragment that has an underscore gets convertet to PascalCase.
ex:
before: __typename: "My_Type" created an interface named My_Type
now: __typename: "My_Type" creates an interface named MyType
After looking further its not just underscores:
__typename: "MY_type" gets converted to an interface named MYType and when referenced in other places converted to MyType
@kamilkisiela I think it's related to one of the changes you did related to pascal-case...
I don't think it's a bug. We decided to PascalCase everything to have naming strategy consistent.
@kamilkisiela Yeah you are right, I'm just not sure if we need to keep and handle _ in a special case.
In pascal-case, _ is not valid, but it usually has a special meaning (private member), so I'm not sure what we should do with it.
I mean, the library we use to PascalCase things, doesn't emit _ so we don't have them
Let's handle that after the weekend, I'm going offline :)
But my generated types.ts file doesn't even compile ? I don't care what the interfaces are named
@Jontem can you please provide an example? why it's not compiling? do you have an error?
Yes i'll make an repro
Repro: https://github.com/Jontem/graphql-codegen-repro
Background for using strange names is that we're auto generating our graphql schema server side from a sql database tables which has some historic names
I can see it now, added it as failing test here: https://github.com/dotansimha/graphql-code-generator/pull/607 , not it will be easier to work on a fix for it :)
Thanks @Jontem .
@Jontem the issue is fixed and merge in #607, I'll release a new version very soon :)
@Jontem fixed and released 0.12.2, can you please test it?
Thank you! The problem i described is gone but i got another issue now. Now some types has 1-3 underscores as prefix. it's just a few of 2000 types i can't see what's the pattern with those are
@dotansimha I've manage to reproduce it. I've updated the repro.
https://github.com/Jontem/graphql-codegen-repro
I see. The underscores are our way to deal with duplicates.
If you are asking for a field called profile multiple times, we want to make sure to create only one Profile interface, and then to append _.
Can you please explain why that's an issue? @Jontem
@dotansimha The problem is that the generated file doesn't compile. In the repro the type "_User" is declared twice
@Jontem fixed in: https://github.com/dotansimha/graphql-code-generator/pull/616 :)
Fixed in 0.12.3 :)
@dotansimha thank you! Everything is working now!