Class: GraphQL::Extras::Test::Loader
- Inherits:
-
Object
- Object
- GraphQL::Extras::Test::Loader
- Defined in:
- lib/graphql/extras/test/loader.rb
Constant Summary collapse
- FragmentNotFoundError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
-
#initialize ⇒ Loader
constructor
A new instance of Loader.
- #load(path) ⇒ Object
- #print(operation) ⇒ Object
Constructor Details
#initialize ⇒ Loader
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
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
7 8 9 |
# File 'lib/graphql/extras/test/loader.rb', line 7 def fragments @fragments end |
#operations ⇒ Object (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 |
#print(operation) ⇒ Object
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 |