Class: GraphQL::Extras::Test::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/extras/test/loader.rb

Constant Summary collapse

FragmentNotFoundError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



10
11
12
13
# File 'lib/graphql/extras/test/loader.rb', line 10

def initialize
  @fragments = {}
  @operations = {}
end

Instance Attribute Details

#fragmentsObject (readonly)

Returns the value of attribute fragments.



7
8
9
# File 'lib/graphql/extras/test/loader.rb', line 7

def fragments
  @fragments
end

#operationsObject (readonly)

Returns the value of attribute operations.



8
9
10
# File 'lib/graphql/extras/test/loader.rb', line 8

def operations
  @operations
end

Instance Method Details

#load(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql/extras/test/loader.rb', line 15

def load(path)
  document = ::GraphQL.parse_file(path)
  document.definitions.each do |node|
    case node
    when Nodes::FragmentDefinition
      fragments[node.name] = node
    when Nodes::OperationDefinition
      operations[node.name] = node
    end
  end
end


27
28
29
30
31
# File 'lib/graphql/extras/test/loader.rb', line 27

def print(operation)
  printer = ::GraphQL::Language::Printer.new
  nodes = [operation, *resolve_fragments(operation)]
  nodes.map { |node| printer.print(node) }.join("\n")
end