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
Copy file name to clipboardExpand all lines: guides/mutations/mutation_classes.md
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -89,3 +89,67 @@ class Types::Mutation < Types::BaseObject
89
89
field :create_comment, mutation:Mutations::CreateComment
90
90
end
91
91
```
92
+
93
+
## Auto-loading arguments
94
+
95
+
In most cases, a GraphQL mutation will act against a given global relay ID. Loading objects from these global relay IDs can require a lot of boilerplate code in the mutation's resolver.
96
+
97
+
An alternative approach is to use the `loads:` argument when defining the argument:
By specifying that the `post_id` argument loads a `Types::Post` object type, a `Post` object will be loaded via {% internal_link "`Schema#object_from_id`", "/schema/definition.html#object-identification-hooks" %} with the provided `post_id`.
116
+
117
+
All arguments that end in `_id` and use the `loads:` method will have their `_id` suffix removed. For example, the mutation resolver above receives a `post` argument which contains the loaded object, instead of a `post_id` argument.
118
+
119
+
The `loads:` option also works with list of IDs, for example:
All arguments that end in `_ids` and use the `loads:` method will have their `_ids` suffix removed and an `s` appended to their name. For example, the mutation resolver above receives a `posts` argument which contains all the loaded objects, instead of a `post_ids` argument.
138
+
139
+
In some cases, you may want to control the resulting argument name. This can be done using the `as:` argument, for example:
0 commit comments