Open astubenbord opened 1 year ago
The escapeDartKeywords only specifies how these Dart keywords defined here should be escaped.
How did you handle this issue? Did you manually change the generated file?
I am willing to assist you address this issue. Do forgive me for the late reply... If I was mentioned on when this issue when it was posted, I would have resolved it as soon as possible
Hi, I could not resolve the issue using this package, therefore I am now using https://github.com/heftapp/graphql_codegen. It also had some issues with escaping keywords prefixed with underscores in some very specific cases but I could resolve it through an easy fix in a PR. I'm also not that familiar with the typescript/npm ecosystem, so using a pure flutter/dart system was more suited for my specific use-case. However, since this package is the more or less "official" way to synchronize the client and server side schema, I'll have an eye on it in the future! I didn't know I had to tag any contributors.
Manually changing the generated files would not have been a viable option in our case since we have to update the schema every now and then, which would introduce lots of overhead or additional scripts to fix these in the generated dart files.
Overall I think the way it is solved in graphql_codegen
is a good compromise, where every property starting with an underscore is prefixed with the defined escape character (like $
) to avoid fields being unintentionally marked as private. I'm not sure how often GraphQL properties start with an underscore, but some content management systems (like the one we use) automatically generate metadata keys with are prefixed with an underscore.
I'm glad you found a solution to you issue.
Before your issue, I had plans to add a feature that will allow you to rename the types and fields in the generated output. This would have worked like this "if you see this field in the Type, then use this name instead and use it original name as the JsonKey in the generated output"...
This would have offered much flexibility to rename fields and types in the generated models.
But I doubt there would be a use-case for it so I didn't proceed with that feature.
Since you have found a solution you are comfortable with, I guess I wouldn't be working on this feature anytime soon until someone else has a need for it.
Which packages are impacted by your issue?
@graphql-codegen/flutter-freezed
Describe the bug
My graphql schema contains meta-data fields, which are prefixed with an '_' (underscore). At the same time, I also have definitions of the same fields as "public" fields, which are not automatically generated, but have the same name as these metadata fields without the underscore prefix. Example:
In the generated
app_models.dart
file, the freezed factory constructor is created with the same field namefield1
twice, causing an error.Your Example Website or App
None
Steps to Reproduce the Bug or Issue
npm init -y
npm run generate
as defined in User GuideExpected behavior
Given the documentation of the
escapeDartKeywords
property used in the providedcodegen.ts
file, I expect the generator to create a class with the two properties$field1
andfield1
.The resulting
app_models.dart
should contain the following code:However, the produced code looks as follows:
Screenshots or Videos
No response
Platform
graphql
version: 16.8.1@graphql-codegen/cli
: 5.0.0@graphql-codegen/flutter-freezed
: 4.0.0Codegen Config File
Additional context
No response