Skip to content

Commit fd8c87a

Browse files
authored
Merge pull request rmosolgo#1811 from cjoudrey/v1.8.8-prep
1.8.8
2 parents a6ed30f + d4a7314 commit fd8c87a

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
### Bug fixes
1010

11+
## 1.8.8 (27 Aug 2018)
12+
13+
### Bug fixes
14+
15+
- When using `RelayClassicMutation`, `client_mutation_id` will no longer be passed to `authorized?` method #1771
16+
- Fix issue in schema upgrader script which would cause `.to_non_null_type` calls in type definition to be ignored #1783
17+
- Ensure enum values respond to `graphql_name` #1792
18+
- Fix infinite resolution bug that could occur when an exception not inheriting from `StandardError` is thrown #1804
19+
20+
### New features
21+
22+
- Add `#path` method to schema members #1766
23+
- Add `as:` argument to allow overriding the name of the argument when using `loads:` #1773
24+
- Add support for list of IDs when using `loads:` in an argument definition #1797
25+
1126
## 1.8.7 (9 Aug 2018)
1227

1328
### Breaking changes

guides/mutations/mutation_classes.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,67 @@ class Types::Mutation < Types::BaseObject
8989
field :create_comment, mutation: Mutations::CreateComment
9090
end
9191
```
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:
98+
99+
```ruby
100+
class Mutations::AddStar < Mutations::BaseMutation
101+
argument :post_id, ID, required: true, loads: Types::Post
102+
103+
field :post, Types::Post, null: true
104+
105+
def resolve(post:)
106+
post.star
107+
108+
{
109+
post: post,
110+
}
111+
end
112+
end
113+
```
114+
115+
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:
120+
121+
```ruby
122+
class Mutations::AddStars < Mutations::BaseMutation
123+
argument :post_ids, [ID], required: true, loads: Types::Post
124+
125+
field :posts, [Types::Post], null: true
126+
127+
def resolve(posts:)
128+
posts.map(&:star)
129+
130+
{
131+
posts: posts,
132+
}
133+
end
134+
end
135+
```
136+
137+
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:
140+
141+
```ruby
142+
class Mutations::AddStar < Mutations::BaseMutation
143+
argument :post_id, ID, required: true, loads: Types::Post, as: :something
144+
145+
field :post, Types::Post, null: true
146+
147+
def resolve(something:)
148+
something.star
149+
150+
{
151+
post: something
152+
}
153+
end
154+
end
155+
```

lib/graphql/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22
module GraphQL
3-
VERSION = "1.8.7"
3+
VERSION = "1.8.8"
44
end

0 commit comments

Comments
 (0)