Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add custom mutation result names - #456

#456
Merged
zachdaniel merged 2 commits into
ash-project:mainash-project/ash_graphql:mainfrom
jaylynntautu:customize-mutation-result-keyjaylynntautu/ash_graphql:customize-mutation-result-keyCopy head branch name to clipboard
Jul 19, 2026
Merged

Add custom mutation result names#456
zachdaniel merged 2 commits into
ash-project:mainash-project/ash_graphql:mainfrom
jaylynntautu:customize-mutation-result-keyjaylynntautu/ash_graphql:customize-mutation-result-keyCopy head branch name to clipboard

Conversation

@jaylynntautu

Copy link
Copy Markdown
Contributor

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

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 result field. With this change, users can optionally configure a custom result field name (for example, offer or offers) while preserving the existing result field 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

Comment thread lib/graphql/resolver.ex Outdated

defp field_matches_path?(field, name) do
field.name == name or
(name == "result" and field.schema_node.identifier == :result)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zachdaniel
zachdaniel merged commit b75f495 into ash-project:main Jul 19, 2026
23 of 24 checks passed
@zachdaniel

Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow customization of key result(s) with mutations

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.