-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
required fields with default value being generated to a nullable field #338
Comments
👋 @subzero911 This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here. |
Hi @subzero911 Please provide some more context to allow me to efficiently help you. This could be an example GraphQL operation and schema along with generated code and what you expect to be generated. |
I don't see how this is not solved by #293? |
I.e I don't agree that the expected code is in fact expected. If you omit the value or supply |
So it basically means that whether I have a |
Yes, but the implementation differs. I.e null values will be not be sent to the server. I believe you confirmed with your backend dev eight months ago that this works by letting the sever fill out the default value? |
Hi again, I checked this twice
So it's legit to write
It's unsafe to rely on server implementation. Example for a Spring server: input TestInput {
nonNullable: String!
nullable: String
nonNullableDefault: String! = "Hello"
nullableDefault: String = "World"
} |
Thank you for your persistence on this issue and for keeping up a good debate. According to your first image, the behaviour for the default value when you provide it to a required field is not defined. As such, you can argue that the engineer writing the schema should not add default values to required fields. Of course, this is not a perfect world, and I recognise that considering that schema for invalid when generating the client is not an option. I am hesitant to generate the default value because it currently isn't a concern for the generator, and making it so carries a few problems:
With these reasons in mind, I think there are two appropriate solutions:
As you are pointing out, different servers might have different interpretations of the spec, so I think it would be reasonable if the solution was configurable. We can add a flag to the config allowing the user to specify their desired behaviour. |
Expected conversion:
required Enum_ColorMode? colorMode,
Actual conversion:
Enum_ColorMode? colorMode,
!
in graphql means "required", not "non-nullable". It can be both required and nullable.I expect that if I have a required field with default value, than I MUST put some value on Dart side, but I CAN put just "null", and a server will substitute it with default value in this case.
related to #293
The text was updated successfully, but these errors were encountered: