mlipscombe/postgraphile-plugin-nested-mutations

pgNestedFieldName and 1:1 relationships

vincenzo opened this issue · 3 comments

Ok, I realise that 1:1 relationships are not an everyday thing (at least not for me), but as I was testing stuff I realised that pgNestedFieldName in this plugin will provide a somewhat erroneous name for a reverse mutation. When we go straight to this point:

return isForward
          ? forwardMutationName || inflection.camelCase(`${tableFieldName}_to_${keyNames.join('_and_')}`)
          : reverseMutationName || inflection.camelCase(`${inflection.pluralize(tableFieldName)}_using_${foreignKeyNames.join('_and_')}`);

when the relationship is 1:1, the reverse will still be using <plural-Field-Name>-using-FK. It's probably more adequate that reverseMutationName follows the same naming convention of forwardMutationName when the relationship is 1:1?

Hopefully I made some sense.

This can be controlled using smart comments. You can set the nested mutation names by @forwardMutationName and @reverseMutationName to anything that suits your schema.

Fair enough, though that's not really the point I am making here. Of course, I can override them, but just saying that by default, in 1:1 context, the naming would be wrong. Of course, you are free to delegate fixing that to smart comments :)

This should now be fixed in the latest version -- one-to-one relationships should now have singular names. If it's not, feel free to reopen.