Skip to content

Commit 47f62c9

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#1448 from michal-samluk/fix_upgrader_parentheses
Parentheses are breaking upgrader
2 parents 0bf83be + 091f6f4 commit 47f62c9

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/graphql/upgrader/member.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def apply(input_text)
161161
keep_looking = true
162162
while keep_looking do
163163
keep_looking = false
164-
input_text = input_text.gsub(/(?<field>(?:field|input_field|return_field|connection|argument)(?:\(.*|.*,))\n\s*(?<next_line>.+)/) do
164+
# Find the `field` call (or other method), and an open paren, but not a close paren, or a comma between arguments
165+
input_text = input_text.gsub(/(?<field>(?:field|input_field|return_field|connection|argument)(?:\([^)]*|.*,))\n\s*(?<next_line>.+)/) do
165166
keep_looking = true
166167
field = $~[:field].chomp
167168
next_line = $~[:next_line]
@@ -177,8 +178,8 @@ def apply(input_text)
177178
class RemoveMethodParensTransform < Transform
178179
def apply(input_text)
179180
input_text.sub(
180-
/(field|input_field|return_field|connection|argument)\( *(.*?) *\) */,
181-
'\1 \2'
181+
/(field|input_field|return_field|connection|argument)\( *(.*?) *\)( *)/,
182+
'\1 \2\3'
182183
)
183184
end
184185
end
@@ -485,7 +486,7 @@ def find_returned_hashes(node, returning:)
485486

486487
class ResolveProcToMethodTransform < Transform
487488
def apply(input_text)
488-
if input_text =~ /resolve ->/
489+
if input_text =~ /resolve\(? ?->/
489490
# - Find the proc literal
490491
# - Get the three argument names (obj, arg, ctx)
491492
# - Get the proc body
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
module Platform
3+
module Objects
4+
Photo = GraphQL::ObjectType.define do
5+
field(:caption, types.String) do
6+
resolve(->(obj, _args, _ctx) { obj.caption })
7+
end
8+
end
9+
end
10+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
module Platform
3+
module Objects
4+
class Photo < Platform::Objects::Base
5+
field :caption, String, null: true
6+
7+
def caption
8+
@object.caption
9+
end
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)