Add custom mutation result names - #456
#456Add custom mutation result names#456zachdaniel merged 2 commits intoash-project:mainash-project/ash_graphql:mainfrom jaylynntautu:customize-mutation-result-keyjaylynntautu/ash_graphql:customize-mutation-result-keyCopy head branch name to clipboard
Conversation
|
|
||
| defp field_matches_path?(field, name) do | ||
| field.name == name or | ||
| (name == "result" and field.schema_node.identifier == :result) |
There was a problem hiding this comment.
Something about this seems off. Been a while since I looked at this code unfortunately 😢 Could this somehow affect cases where there is an actual field somewhere called :result? I'm wondering if the right answer is actually to rename the result field's identifier to :result and handle the effects of that elsewhere.
Granted this is less complex and requires less changes if we just change the presented name.
Could you think through the first bit above and LMK if there are cases where this is an issue?
There was a problem hiding this comment.
Ok yes the identifier fallback could be too broad in cases where a resource has an actual field named :result.
I removed that fallback entirely, so field_matches_path?/2 now only matches field.name == name.
Instead of changing the schema identifier, I now thread the configured mutation result field name through the create/update/destroy selection and load traversal. The internal identifier remains :result, and resolver return maps remain %{result: value}.
I also added a regression test with a public resource attribute named :result to cover the collision case you called out.
|
🚀 Thank you for your contribution! 🚀 |
Contributor checklist
Leave anything that you believe does not apply unchecked.
Summary
This PR adds support for customizing the GraphQL result field name returned by mutations.
Previously, all mutation payloads exposed the returned resource under the generic
resultfield. With this change, users can optionally configure a custom result field name (for example,offeroroffers) while preserving the existingresultfield as the default for backwards compatibility.This change adds the new mutation DSL option, updates GraphQL schema generation to honor the configured field name, and includes tests covering both the default behavior and customized result names.
Closes #57