Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
213 stars 49 forks source link

[Feature request] Flag for custom scalar types in dotnet tool CLI #116

Closed thatvineyard closed 1 year ago

thatvineyard commented 1 year ago

Hi, love the tool so far and am inspired by the amount of work you put into it 😊

I'm admittedly a bit out of my depth since I know nothing about c# source generation generation, but I've been using dotnet tool run graphql-client-generator ... to generate files and it's been working great for the majority of files generated!

Unfortunately the schema I'm generating from has a custom scalar called Time which results in a object type in the generated code, and I was wondering if there is support to map this scalar to a DateTime using the cli command.

I saw this issue #73 and saw that there was support for this when using source generation, but not when using the CLI.

I'm using version 0.9.13 of the dotnet tool.

thatvineyard commented 1 year ago

I did try using --classMapping <classMapping> but it didn't work since it's a scalar and not a type

Husqvik commented 1 year ago

Ok, the source generator has option to specify custom scalar types using RegexScalarFieldTypeMappingProvider.gql.config.json file. I could add similar option for using the console tool. So you can then define rules like

[
  {
    "patternBaseType": ".+",
    "patternValueType": "^Time$",
    "patternValueName": ".+",
    "netTypeName": "DateTime?",
    "formatMask": null
  }
]

and use the file as an input parameter.

Does this sound good?

thatvineyard commented 1 year ago

Yeah that sounds like a good solution!

Husqvik commented 1 year ago

https://www.nuget.org/packages/GraphQlClientGenerator.Tool/0.9.14

Husqvik commented 1 year ago

use --regexScalarFieldTypeMappingConfigurationFile <fileName>