You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Input Types constructors that have ambiguous signatures (for instance, 2 arguments of the same type), there is a risk that the order will change when getting a new version of the schema, because the generated code follows the order of the schema.
e.g. class MyInput(val since: Int, val count: Int) could become class MyInput(val count: Int, val since: Int) and calling code MyInput(0, 42) would still compile but become incorrect - whereas MyInput(since = 0, count = 42) would be safe.
Therefore a good practice is to use named arguments, or the input type builders (which we want to encourage because it is also nicer to use with regards to optionals).
The IJ plugin can mark unsafe constructor calls with a warning a suggest 2 quickfixes:
add argument names
change to builder call (note: potentially this one won't compile since input type builders is a codegen option that is off by default - we'd need a way to hint the user about how to turn it on)
The warning should probably be present only when there's at least 2 arguments, and an ambiguity. Or it can be present at all times, but with a soft severity if it's not ambiguous, and warn if it is.
2 can be an intention always present on Input Type constructors independently of the warning - helpful for users wanting to migrate to the builder pattern, they'll be able to do so globally on their project.
The text was updated successfully, but these errors were encountered:
Description
Context : #4659
When using Input Types constructors that have ambiguous signatures (for instance, 2 arguments of the same type), there is a risk that the order will change when getting a new version of the schema, because the generated code follows the order of the schema.
e.g.
class MyInput(val since: Int, val count: Int)
could becomeclass MyInput(val count: Int, val since: Int)
and calling codeMyInput(0, 42)
would still compile but become incorrect - whereasMyInput(since = 0, count = 42)
would be safe.Therefore a good practice is to use named arguments, or the input type builders (which we want to encourage because it is also nicer to use with regards to optionals).
The IJ plugin can mark unsafe constructor calls with a warning a suggest 2 quickfixes:
The warning should probably be present only when there's at least 2 arguments, and an ambiguity. Or it can be present at all times, but with a soft severity if it's not ambiguous, and warn if it is.
2 can be an intention always present on Input Type constructors independently of the warning - helpful for users wanting to migrate to the builder pattern, they'll be able to do so globally on their project.
The text was updated successfully, but these errors were encountered: