Skip to content

Commit 0b61309

Browse files
committed
Replace -> (...) with ->(...) to be Ruby 1.9.3 compatible
See http://ruby-journal.com/becareful-with-space-in-lambda-hash-rocket-syntax-between-ruby-1-dot-9-and-2-dot-0/ for more info.
1 parent 4a3d572 commit 0b61309

File tree

86 files changed

+238
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+238
-238
lines changed

CHANGELOG-relay.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
```ruby
110110
field :cities, CityType.connection_type do
111111
argument :order, types.String, default_value: "name"
112-
resolve -> (obj, args, ctx) {
112+
resolve ->(obj, args, ctx) {
113113
obj.order(args[:order])
114114
}
115115
end

CHANGELOG.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
Previously, it was called with two arguments:
1818

1919
```ruby
20-
resolve -> (inputs, ctx) { ... }
20+
resolve ->(inputs, ctx) { ... }
2121
```
2222

2323
Now, it's called with three inputs:
2424

2525
```ruby
26-
resolve -> (obj, inputs, ctx) { ... }
26+
resolve ->(obj, inputs, ctx) { ... }
2727
```
2828

2929
`obj` is the value of `root_value:` given to `Schema#execute`, as with other root-level fields.
@@ -92,11 +92,11 @@
9292
```ruby
9393
MySchema = GraphQL::Schema.define do
9494
# Fetch an object by UUID
95-
object_from_id -> (id, ctx) {
95+
object_from_id ->(id, ctx) {
9696
MyApp::RelayLookup.find(id)
9797
}
9898
# Generate a UUID for this object
99-
id_from_object -> (obj, type_defn, ctx) {
99+
id_from_object ->(obj, type_defn, ctx) {
100100
MyApp::RelayLookup.to_id(obj)
101101
}
102102
end
@@ -106,14 +106,14 @@
106106

107107
```ruby
108108
MySchema = GraphQL::Schema.define do
109-
object_from_id -> (id, ctx) {
109+
object_from_id ->(id, ctx) {
110110
# Break the id into its parts:
111111
type_name, object_id = GraphQL::Schema::UniqueWithinType.decode(id)
112112
# Fetch the identified object
113113
# ...
114114
}
115115
116-
id_from_object -> (obj, type_defn, ctx) {
116+
id_from_object ->(obj, type_defn, ctx) {
117117
# Provide the the type name & the object's `id`:
118118
GraphQL::Schema::UniqueWithinType.encode(type_defn.name, obj.id)
119119
}
@@ -133,7 +133,7 @@
133133
```ruby
134134
MySchema = GraphQL::Schema.define do
135135
# ...
136-
resolve_type -> (obj, ctx) {
136+
resolve_type ->(obj, ctx) {
137137
# based on `obj` and `ctx`,
138138
# figure out which GraphQL type to use
139139
# and return the type
@@ -346,19 +346,19 @@
346346
347347
```ruby
348348
GraphQL::Relay::GlobalNodeIdentification.define do
349-
type_from_object -> (obj) { ... }
349+
type_from_object ->(obj) { ... }
350350
end
351351
352352
GraphQL::InterfaceType.define do
353-
resolve_type -> (obj, ctx) { ... }
353+
resolve_type ->(obj, ctx) { ... }
354354
end
355355
```
356356
357357
After:
358358
359359
```ruby
360360
GraphQL::Schema.define do
361-
resolve_type -> (obj, ctx) { ... }
361+
resolve_type ->(obj, ctx) { ... }
362362
end
363363
```
364364
@@ -625,9 +625,9 @@
625625

626626
```ruby
627627
# Previous coerce behavior for scalars:
628-
GraphQL::BOOLEAN_TYPE.coerce = -> (value) { !!value }
629-
GraphQL::ID_TYPE.coerce = -> (value) { value.to_s }
630-
GraphQL::STRING_TYPE.coerce = -> (value) { value.to_s }
628+
GraphQL::BOOLEAN_TYPE.coerce = ->(value) { !!value }
629+
GraphQL::ID_TYPE.coerce = ->(value) { value.to_s }
630+
GraphQL::STRING_TYPE.coerce = ->(value) { value.to_s }
631631
# INT_TYPE and FLOAT_TYPE were unchanged
632632
```
633633

guides/code_reuse.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Many examples use a Proc literal for a field's `resolve`, for example:
1919
```ruby
2020
field :name, types.String do
2121
# Resolve taking a Proc literal:
22-
resolve -> (obj, args, ctx) { obj.name }
22+
resolve ->(obj, args, ctx) { obj.name }
2323
end
2424
```
2525

@@ -66,7 +66,7 @@ Or, you can generate the `resolve` Proc dynamically:
6666
```ruby
6767
# @return [Proc] A resolve proc which calls `method_name` on `obj`
6868
def resolve_with_method(method_name)
69-
-> (obj, args, ctx) { obj.public_send(method_name) }
69+
->(obj, args, ctx) { obj.public_send(method_name) }
7070
end
7171

7272
# ...
@@ -163,7 +163,7 @@ module Auth
163163
# @yieldreturn [Object] The return value for this field
164164
# @return [Proc] the passed-in block, modified to check for `can_read?(item_name)`
165165
def self.can_read(item_name, &block)
166-
-> (obj, args, ctx) do
166+
->(obj, args, ctx) do
167167
if ctx[:current_user].can_read?(item_name)
168168
# continue to the next call:
169169
block.call(obj, args, ctx)

guides/defining_your_schema.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ In order for your schema to expose members of an interface, it must be able to d
5858
```ruby
5959
MySchema = GraphQL::Schema.define do
6060
# ...
61-
resolve_type -> (object, ctx) {
61+
resolve_type ->(object, ctx) {
6262
# for example, look up types by class name
6363
type_name = object.class.name
6464
MySchema.types[type_name]
@@ -178,7 +178,7 @@ field :comments do
178178

179179
argument :moderated, types.Boolean, default_value: true
180180

181-
resolve -> (obj, args, ctx) do
181+
resolve ->(obj, args, ctx) do
182182
Comment.where(
183183
post_id: obj.id,
184184
moderated: args["moderated"]
@@ -324,7 +324,7 @@ Query analyzers are like middleware for the validation phase. They're called at
324324
The minimal API is `.call(memo, visit_type, internal_representation_node)`. For example:
325325

326326
```ruby
327-
ast_node_logger = -> (memo, visit_type, internal_representation_node) {
327+
ast_node_logger = ->(memo, visit_type, internal_representation_node) {
328328
if visit_type == :enter
329329
puts "Visiting #{internal_representation_node.name}!"
330330
end
@@ -409,7 +409,7 @@ MySchema = GraphQL::Schema.define do
409409
# ...
410410
# Use the type's declared `resolves_to_class_names`
411411
# to figure out if `obj` is a member of that type
412-
resolve_type -> (obj, ctx) {
412+
resolve_type ->(obj, ctx) {
413413
class_name = obj.class.name
414414
MySchema.types.values.find { |type| type.metadata[:resolves_to_class_names].include?(class_name) }
415415
}

guides/executing_queries.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ These values will be accessible by key inside `resolve` functions. For example,
3939
SecretStringField = GraphQL::Field.new do |f|
4040
f.type !GraphQL::STRING_TYPE
4141
f.description "A string that's only visible to authorized users"
42-
f.resolve -> (obj, args, ctx) { ctx[:current_user].authorized? ? obj.secret_string : nil }
42+
f.resolve ->(obj, args, ctx) { ctx[:current_user].authorized? ? obj.secret_string : nil }
4343
end
4444
```
4545

guides/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ QueryRoot = GraphQL::ObjectType.define do
6666
type PostType
6767
description "Find a Post by id"
6868
argument :id, !types.ID
69-
resolve -> (object, arguments, context) {
69+
resolve ->(object, arguments, context) {
7070
Post.find(arguments["id"])
7171
}
7272
end

guides/relay.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ You must provide a function for generating UUIDs and fetching objects with them.
2222

2323
```ruby
2424
MySchema = GraphQL::Schema.define do
25-
id_from_object -> (object, type_definition, query_ctx) {
25+
id_from_object ->(object, type_definition, query_ctx) {
2626
# Call your application's UUID method here
2727
# It should return a string
2828
MyApp::GlobalId.encrypt(object.class.name, object.id)
2929
}
3030

31-
object_from_id -> (id, query_ctx) {
31+
object_from_id ->(id, query_ctx) {
3232
class_name, item_id = MyApp::GlobalId.decrypt(id)
3333
# "Post" => Post.find(id)
3434
Object.const_get(class_name).find(item_id)
@@ -41,11 +41,11 @@ An unencrypted ID generator is provided in the gem. It uses `Base64` to encode v
4141
```ruby
4242
MySchema = GraphQL::Schema.define do
4343
# Create UUIDs by joining the type name & ID, then base64-encoding it
44-
id_from_object -> (object, type_definition, query_ctx) {
44+
id_from_object ->(object, type_definition, query_ctx) {
4545
GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
4646
}
4747

48-
object_from_id -> (id, query_ctx) {
48+
object_from_id ->(id, query_ctx) {
4949
type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
5050
# Now, based on `type_name` and `id`
5151
# find an object in your application
@@ -129,7 +129,7 @@ connection :featured_comments, CommentType.connection_type do
129129
argument :since, types.String
130130

131131
# Return an Array or ActiveRecord::Relation
132-
resolve -> (post, args, ctx) {
132+
resolve ->(post, args, ctx) {
133133
comments = post.comments.featured
134134

135135
if args[:since]
@@ -158,7 +158,7 @@ PostConnectionWithTotalCountType = PostType.define_connection do
158158
field :totalCount do
159159
type types.Int
160160
# `obj` is the Connection, `obj.object` is the collection of Posts
161-
resolve -> (obj, args, ctx) { obj.object.count }
161+
resolve ->(obj, args, ctx) { obj.object.count }
162162
end
163163
end
164164

@@ -182,7 +182,7 @@ If you need custom fields on `edge`s, you can define an edge type and pass it to
182182
MembershipSinceEdgeType = TeamType.define_edge do
183183
name "MembershipSinceEdge"
184184
field :memberSince, types.Int, "The date that this person joined this team" do
185-
resolve -> (obj, args, ctx) {
185+
resolve ->(obj, args, ctx) {
186186
obj # => GraphQL::Relay::Edge instance
187187
person = obj.parent
188188
team = obj.node
@@ -398,7 +398,7 @@ To define a mutation, use `GraphQL::Relay::Mutation.define`. Inside the block, y
398398
- `name`, which will name the mutation field & derived types
399399
- `input_field`s, which will be applied to the derived `InputObjectType`
400400
- `return_field`s, which will be applied to the derived `ObjectType`
401-
- `resolve(-> (obj, inputs, ctx) { ... })`, the mutation which will actually happen
401+
- `resolve(->(obj, inputs, ctx) { ... })`, the mutation which will actually happen
402402

403403

404404
For example:
@@ -420,7 +420,7 @@ AddCommentMutation = GraphQL::Relay::Mutation.define do
420420

421421
# The resolve proc is where you alter the system state.
422422
# `object` is the `root_value:` passed to `Schema.execute`.
423-
resolve -> (object, inputs, ctx) {
423+
resolve ->(object, inputs, ctx) {
424424
post = Post.find(inputs[:postId])
425425
comment = post.comments.create!(author_id: inputs[:authorId], content: inputs[:content])
426426

@@ -448,7 +448,7 @@ Instead of specifying `return_field`s, you can specify a `return_type` for a mut
448448
CreateUser = GraphQL::Relay::Mutation.define do
449449
return_type UserMutationResultType
450450
# ...
451-
resolve -> (obj, input, ctx) {
451+
resolve ->(obj, input, ctx) {
452452
user = User.create(input)
453453
# this object will be treated as `UserMutationResultType`
454454
UserMutationResult.new(user, client_mutation_id: input[:clientMutationId])

guides/security.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Always limit the number of items which can be returned from a list field. For ex
1111
```ruby
1212
field :items, types[ItemType] do
1313
argument :limit, types.Int, default_value: 20
14-
resolve -> (obj, args, ctx) {
14+
resolve ->(obj, args, ctx) {
1515
# Cap the number of items at 30
1616
limit = [args[:limit], 30].min
1717
obj.items.limit(limit)
@@ -52,7 +52,7 @@ field :top_score, types.Int, complexity: 10
5252
# Dynamic complexity:
5353
field :top_scorers, types[PlayerType] do
5454
argument :limit, types.Int, default_value: 5
55-
complexity -> (ctx, args, child_complexity) {
55+
complexity ->(ctx, args, child_complexity) {
5656
if ctx[:current_user].staff?
5757
# no limit for staff users
5858
0

guides/testing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For example, consider a field which calculates its own value:
1919
PostType = GraphQL::ObjectType.define do
2020
# ...
2121
field :isTrending, types.Boolean do
22-
resolve -> (obj, args, ctx) {
22+
resolve ->(obj, args, ctx) {
2323
recent_comments = comments.where("created_at < ?", 1.day.ago)
2424
recent_comments.count > 100
2525
}
@@ -50,7 +50,7 @@ end
5050
PostType = GraphQL::ObjectType.define do
5151
# ...
5252
field :isTrending, types.Boolean do
53-
resolve -> (obj, args, ctx) {
53+
resolve ->(obj, args, ctx) {
5454
# Use the Post::Trending class to calculate the value
5555
Post::Trending.new(obj).value
5656
}

lib/graphql/analysis/max_query_complexity.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Analysis
1111
#
1212
class MaxQueryComplexity < GraphQL::Analysis::QueryComplexity
1313
def initialize(max_complexity)
14-
disallow_excessive_complexity = -> (query, complexity) {
14+
disallow_excessive_complexity = ->(query, complexity) {
1515
if complexity > max_complexity
1616
GraphQL::AnalysisError.new("Query has complexity of #{complexity}, which exceeds max complexity of #{max_complexity}")
1717
else

lib/graphql/analysis/max_query_depth.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Analysis
1111
#
1212
class MaxQueryDepth < GraphQL::Analysis::QueryDepth
1313
def initialize(max_depth)
14-
disallow_excessive_depth = -> (query, depth) {
14+
disallow_excessive_depth = ->(query, depth) {
1515
if depth > max_depth
1616
GraphQL::AnalysisError.new("Query has depth of #{depth}, which exceeds max depth of #{max_depth}")
1717
else

lib/graphql/boolean_type.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
name "Boolean"
33
description "Represents `true` or `false` values."
44

5-
coerce_input -> (value) { (value == true || value == false) ? value : nil }
6-
coerce_result -> (value) { !!value }
5+
coerce_input ->(value) { (value == true || value == false) ? value : nil }
6+
coerce_result ->(value) { !!value }
77
end

lib/graphql/define/instance_definable.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Define
2525
# # These attrs will be defined with plain setters, `{attr}=`
2626
# :make, :model,
2727
# # This attr has a custom definition which applies the config to the target
28-
# doors: -> (car, doors_count) { doors_count.times { car.doors << Door.new } }
28+
# doors: ->(car, doors_count) { doors_count.times { car.doors << Door.new } }
2929
# )
3030
#
3131
# def initialize
@@ -85,7 +85,7 @@ def define(**kwargs, &block)
8585
# make sure the previous definition_proc was executed:
8686
ensure_defined
8787

88-
@definition_proc = -> (obj) {
88+
@definition_proc = ->(obj) {
8989
kwargs.each do |keyword, value|
9090
public_send(keyword, value)
9191
end

lib/graphql/enum_type.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module GraphQL
2828
# @example Defining an enum input
2929
# field :coders, types[CoderType] do
3030
# argument :knowing, types[LanguageType]
31-
# resolve -> (obj, args, ctx) {
31+
# resolve ->(obj, args, ctx) {
3232
# Coder.where(language: args[:knowing])
3333
# }
3434
# end
@@ -51,7 +51,7 @@ module GraphQL
5151
#
5252
# # Now, resolve functions will receive `:rb` instead of `"RUBY"`
5353
# field :favoriteLanguage, LanguageEnum
54-
# resolve -> (obj, args, ctx) {
54+
# resolve ->(obj, args, ctx) {
5555
# args[:favoriteLanguage] # => :rb
5656
# }
5757
#

0 commit comments

Comments
 (0)