Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/graphql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ def parse(str, filename = nil, lineno = nil)

# Replace Ruby constant reference with GraphQL fragment names,
# while populating `definition_dependencies` with
# GraphQL Fragment ASTs which this operation depends on
str = str.gsub(/\.\.\.([a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)*)/) do
# GraphQL Fragment ASTs which this operation depends on.
#
# GraphQL forbids naming a fragment "on", so "...on" followed by a word
# boundary is unambiguously an inline fragment, never a spread
# referencing constant "On".
str = str.gsub(/\.\.\.(?!on\b)([a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)*)/) do
match = Regexp.last_match
const_name = match[1]

Expand Down
34 changes: 34 additions & 0 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ def test_client_parse_anonymous_query
assert_equal(query_string, Temp::UserQuery.document.to_query_string)
end

def test_client_parse_inline_fragment_without_space_before_on
Temp.const_set :NodeQuery, @client.parse(<<-'GRAPHQL')
query {
node(id: "1") {
id
...on User {
name
}
... on Organization {
name
}
}
}
GRAPHQL

query_string = <<-'GRAPHQL'.gsub(/^ /, "").chomp
query TestClient__Temp__NodeQuery {
node(id: "1") {
__typename
id
... on User {
name
}
... on Organization {
name
}
}
}
GRAPHQL

assert_equal(query_string, @client.document.to_query_string)
assert_equal(query_string, Temp::NodeQuery.document.to_query_string)
end

def test_client_parse_query_document
Temp.const_set :UserDocument, @client.parse(<<-'GRAPHQL')
query GetUser {
Expand Down