Skip to content

Commit

Permalink
Replace -> (...) with ->(...) to be Ruby 1.9.3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
astorije committed Oct 16, 2016
1 parent 4a3d572 commit 0b61309
Show file tree
Hide file tree
Showing 86 changed files with 238 additions and 238 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG-relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
```ruby
field :cities, CityType.connection_type do
argument :order, types.String, default_value: "name"
resolve -> (obj, args, ctx) {
resolve ->(obj, args, ctx) {
obj.order(args[:order])
}
end
Expand Down
26 changes: 13 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
Previously, it was called with two arguments:

```ruby
resolve -> (inputs, ctx) { ... }
resolve ->(inputs, ctx) { ... }
```

Now, it's called with three inputs:

```ruby
resolve -> (obj, inputs, ctx) { ... }
resolve ->(obj, inputs, ctx) { ... }
```

`obj` is the value of `root_value:` given to `Schema#execute`, as with other root-level fields.
Expand Down Expand Up @@ -92,11 +92,11 @@
```ruby
MySchema = GraphQL::Schema.define do
# Fetch an object by UUID
object_from_id -> (id, ctx) {
object_from_id ->(id, ctx) {
MyApp::RelayLookup.find(id)
}
# Generate a UUID for this object
id_from_object -> (obj, type_defn, ctx) {
id_from_object ->(obj, type_defn, ctx) {
MyApp::RelayLookup.to_id(obj)
}
end
Expand All @@ -106,14 +106,14 @@

```ruby
MySchema = GraphQL::Schema.define do
object_from_id -> (id, ctx) {
object_from_id ->(id, ctx) {
# Break the id into its parts:
type_name, object_id = GraphQL::Schema::UniqueWithinType.decode(id)
# Fetch the identified object
# ...
}
id_from_object -> (obj, type_defn, ctx) {
id_from_object ->(obj, type_defn, ctx) {
# Provide the the type name & the object's `id`:
GraphQL::Schema::UniqueWithinType.encode(type_defn.name, obj.id)
}
Expand All @@ -133,7 +133,7 @@
```ruby
MySchema = GraphQL::Schema.define do
# ...
resolve_type -> (obj, ctx) {
resolve_type ->(obj, ctx) {
# based on `obj` and `ctx`,
# figure out which GraphQL type to use
# and return the type
Expand Down Expand Up @@ -346,19 +346,19 @@
```ruby
GraphQL::Relay::GlobalNodeIdentification.define do
type_from_object -> (obj) { ... }
type_from_object ->(obj) { ... }
end
GraphQL::InterfaceType.define do
resolve_type -> (obj, ctx) { ... }
resolve_type ->(obj, ctx) { ... }
end
```
After:
```ruby
GraphQL::Schema.define do
resolve_type -> (obj, ctx) { ... }
resolve_type ->(obj, ctx) { ... }
end
```
Expand Down Expand Up @@ -625,9 +625,9 @@

```ruby
# Previous coerce behavior for scalars:
GraphQL::BOOLEAN_TYPE.coerce = -> (value) { !!value }
GraphQL::ID_TYPE.coerce = -> (value) { value.to_s }
GraphQL::STRING_TYPE.coerce = -> (value) { value.to_s }
GraphQL::BOOLEAN_TYPE.coerce = ->(value) { !!value }
GraphQL::ID_TYPE.coerce = ->(value) { value.to_s }
GraphQL::STRING_TYPE.coerce = ->(value) { value.to_s }
# INT_TYPE and FLOAT_TYPE were unchanged
```

Expand Down
6 changes: 3 additions & 3 deletions guides/code_reuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Many examples use a Proc literal for a field's `resolve`, for example:
```ruby
field :name, types.String do
# Resolve taking a Proc literal:
resolve -> (obj, args, ctx) { obj.name }
resolve ->(obj, args, ctx) { obj.name }
end
```

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

# ...
Expand Down Expand Up @@ -163,7 +163,7 @@ module Auth
# @yieldreturn [Object] The return value for this field
# @return [Proc] the passed-in block, modified to check for `can_read?(item_name)`
def self.can_read(item_name, &block)
-> (obj, args, ctx) do
->(obj, args, ctx) do
if ctx[:current_user].can_read?(item_name)
# continue to the next call:
block.call(obj, args, ctx)
Expand Down
8 changes: 4 additions & 4 deletions guides/defining_your_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ In order for your schema to expose members of an interface, it must be able to d
```ruby
MySchema = GraphQL::Schema.define do
# ...
resolve_type -> (object, ctx) {
resolve_type ->(object, ctx) {
# for example, look up types by class name
type_name = object.class.name
MySchema.types[type_name]
Expand Down Expand Up @@ -178,7 +178,7 @@ field :comments do

argument :moderated, types.Boolean, default_value: true

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

```ruby
ast_node_logger = -> (memo, visit_type, internal_representation_node) {
ast_node_logger = ->(memo, visit_type, internal_representation_node) {
if visit_type == :enter
puts "Visiting #{internal_representation_node.name}!"
end
Expand Down Expand Up @@ -409,7 +409,7 @@ MySchema = GraphQL::Schema.define do
# ...
# Use the type's declared `resolves_to_class_names`
# to figure out if `obj` is a member of that type
resolve_type -> (obj, ctx) {
resolve_type ->(obj, ctx) {
class_name = obj.class.name
MySchema.types.values.find { |type| type.metadata[:resolves_to_class_names].include?(class_name) }
}
Expand Down
2 changes: 1 addition & 1 deletion guides/executing_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ These values will be accessible by key inside `resolve` functions. For example,
SecretStringField = GraphQL::Field.new do |f|
f.type !GraphQL::STRING_TYPE
f.description "A string that's only visible to authorized users"
f.resolve -> (obj, args, ctx) { ctx[:current_user].authorized? ? obj.secret_string : nil }
f.resolve ->(obj, args, ctx) { ctx[:current_user].authorized? ? obj.secret_string : nil }
end
```

Expand Down
2 changes: 1 addition & 1 deletion guides/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ QueryRoot = GraphQL::ObjectType.define do
type PostType
description "Find a Post by id"
argument :id, !types.ID
resolve -> (object, arguments, context) {
resolve ->(object, arguments, context) {
Post.find(arguments["id"])
}
end
Expand Down
20 changes: 10 additions & 10 deletions guides/relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ You must provide a function for generating UUIDs and fetching objects with them.

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

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

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

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

if args[:since]
Expand Down Expand Up @@ -158,7 +158,7 @@ PostConnectionWithTotalCountType = PostType.define_connection do
field :totalCount do
type types.Int
# `obj` is the Connection, `obj.object` is the collection of Posts
resolve -> (obj, args, ctx) { obj.object.count }
resolve ->(obj, args, ctx) { obj.object.count }
end
end

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


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

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

Expand Down Expand Up @@ -448,7 +448,7 @@ Instead of specifying `return_field`s, you can specify a `return_type` for a mut
CreateUser = GraphQL::Relay::Mutation.define do
return_type UserMutationResultType
# ...
resolve -> (obj, input, ctx) {
resolve ->(obj, input, ctx) {
user = User.create(input)
# this object will be treated as `UserMutationResultType`
UserMutationResult.new(user, client_mutation_id: input[:clientMutationId])
Expand Down
4 changes: 2 additions & 2 deletions guides/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Always limit the number of items which can be returned from a list field. For ex
```ruby
field :items, types[ItemType] do
argument :limit, types.Int, default_value: 20
resolve -> (obj, args, ctx) {
resolve ->(obj, args, ctx) {
# Cap the number of items at 30
limit = [args[:limit], 30].min
obj.items.limit(limit)
Expand Down Expand Up @@ -52,7 +52,7 @@ field :top_score, types.Int, complexity: 10
# Dynamic complexity:
field :top_scorers, types[PlayerType] do
argument :limit, types.Int, default_value: 5
complexity -> (ctx, args, child_complexity) {
complexity ->(ctx, args, child_complexity) {
if ctx[:current_user].staff?
# no limit for staff users
0
Expand Down
4 changes: 2 additions & 2 deletions guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For example, consider a field which calculates its own value:
PostType = GraphQL::ObjectType.define do
# ...
field :isTrending, types.Boolean do
resolve -> (obj, args, ctx) {
resolve ->(obj, args, ctx) {
recent_comments = comments.where("created_at < ?", 1.day.ago)
recent_comments.count > 100
}
Expand Down Expand Up @@ -50,7 +50,7 @@ end
PostType = GraphQL::ObjectType.define do
# ...
field :isTrending, types.Boolean do
resolve -> (obj, args, ctx) {
resolve ->(obj, args, ctx) {
# Use the Post::Trending class to calculate the value
Post::Trending.new(obj).value
}
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/analysis/max_query_complexity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Analysis
#
class MaxQueryComplexity < GraphQL::Analysis::QueryComplexity
def initialize(max_complexity)
disallow_excessive_complexity = -> (query, complexity) {
disallow_excessive_complexity = ->(query, complexity) {
if complexity > max_complexity
GraphQL::AnalysisError.new("Query has complexity of #{complexity}, which exceeds max complexity of #{max_complexity}")
else
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/analysis/max_query_depth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Analysis
#
class MaxQueryDepth < GraphQL::Analysis::QueryDepth
def initialize(max_depth)
disallow_excessive_depth = -> (query, depth) {
disallow_excessive_depth = ->(query, depth) {
if depth > max_depth
GraphQL::AnalysisError.new("Query has depth of #{depth}, which exceeds max depth of #{max_depth}")
else
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/boolean_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
name "Boolean"
description "Represents `true` or `false` values."

coerce_input -> (value) { (value == true || value == false) ? value : nil }
coerce_result -> (value) { !!value }
coerce_input ->(value) { (value == true || value == false) ? value : nil }
coerce_result ->(value) { !!value }
end
4 changes: 2 additions & 2 deletions lib/graphql/define/instance_definable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Define
# # These attrs will be defined with plain setters, `{attr}=`
# :make, :model,
# # This attr has a custom definition which applies the config to the target
# doors: -> (car, doors_count) { doors_count.times { car.doors << Door.new } }
# doors: ->(car, doors_count) { doors_count.times { car.doors << Door.new } }
# )
#
# def initialize
Expand Down Expand Up @@ -85,7 +85,7 @@ def define(**kwargs, &block)
# make sure the previous definition_proc was executed:
ensure_defined

@definition_proc = -> (obj) {
@definition_proc = ->(obj) {
kwargs.each do |keyword, value|
public_send(keyword, value)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/enum_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module GraphQL
# @example Defining an enum input
# field :coders, types[CoderType] do
# argument :knowing, types[LanguageType]
# resolve -> (obj, args, ctx) {
# resolve ->(obj, args, ctx) {
# Coder.where(language: args[:knowing])
# }
# end
Expand All @@ -51,7 +51,7 @@ module GraphQL
#
# # Now, resolve functions will receive `:rb` instead of `"RUBY"`
# field :favoriteLanguage, LanguageEnum
# resolve -> (obj, args, ctx) {
# resolve ->(obj, args, ctx) {
# args[:favoriteLanguage] # => :rb
# }
#
Expand Down
Loading

0 comments on commit 0b61309

Please sign in to comment.