Netflix / dgs-codegen

Apache License 2.0
177 stars 92 forks source link

Code is not compiling after aliases were added to projections #681

Closed njuro closed 2 months ago

njuro commented 2 months ago

Hi, in patch update 6.1.7, support for aliases was added to query projections (https://github.com/Netflix/dgs-codegen/pull/676).

This seems like an innocent change, since the _alias parameter has default value (null), however it will cause problems when the projection is used in user code without explicitly named arguments. That's caused by the fact that the _alias parameter was added to the beginning of the parameter list, not to the end. Example:

Before 6.1.7: Generated projection(foo: String), called in user code as projection("bar") - compiles

After 6.1.7.: Generated projection(_alias: String = null, foo: String), called in code as projection("bar") - won't compile, because bar will be passed as _alias, leaving the required parameter foo undefined.

The fix on the user side is simple, we just need to use named argument like this: projection(foo = "bar") and everything works again. But for larger projects it can be quite annoying, especially since this isn't something that can be mass replaced and you need to fix it case by case.

Therefore I propose to revert this update and either add the _alias parameter to the end of the parameter list, or to release it as major version change, not patch.

srinivasankavitha commented 2 months ago

Thanks for flagging this @njuro. @mbossenbroek - what do you think? I can revert or if you are ok with moving the _alias to the end, we can go with that so it's not a breaking change.

srinivasankavitha commented 2 months ago

https://github.com/Netflix/dgs-codegen/pull/682#pullrequestreview-2015434254

njuro commented 2 months ago

That fixes it, thank you