Module: GraphQL::Relay::Parser

Defined in:
lib/graphql/relay/parser.rb

Constant Summary collapse

ANONYMOUS_SENTINEL =
"__anonymous__".freeze

Class Method Summary collapse

Class Method Details

.parse(str) ⇒ Object

Public: Extended GraphQL.parse that supports Relay style anonymous fragments.

TODO: See about getting support for this upstreamed to the graphql-ruby gem.

str - A GraphQL String

Returns a GraphQL::Language::Nodes::Document.



17
18
19
20
21
22
23
24
# File 'lib/graphql/relay/parser.rb', line 17

def self.parse(str)
  str = str.sub(/fragment on /, "fragment #{ANONYMOUS_SENTINEL} on ")
  document = GraphQL.parse(str)
  document.definitions.each do |node|
    node.name = nil if node.name == ANONYMOUS_SENTINEL
  end
  document
end