Class: GraphQL::Client::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, client:, source:) ⇒ Definition

Returns a new instance of Definition.



23
24
25
26
27
28
# File 'lib/graphql/client.rb', line 23

def initialize(name:, client:, source:)
  @name = name
  @client = client
  @_nodes = @client._parse(@name, source)
  @query_result = GraphQL::Client::QueryResult.wrap(@_nodes.first, name: name)
end

Instance Attribute Details

#_nodesObject (readonly)

Returns the value of attribute _nodes.



30
31
32
# File 'lib/graphql/client.rb', line 30

def _nodes
  @_nodes
end

Instance Method Details

#documentObject



40
41
42
# File 'lib/graphql/client.rb', line 40

def document
  @document ||= Language::OperationSlice.slice(@client.document, operation_name).deep_freeze
end

#new(*args) ⇒ Object



44
45
46
# File 'lib/graphql/client.rb', line 44

def new(*args)
  @query_result.new(*args)
end

#operation_nameObject



32
33
34
35
36
37
38
# File 'lib/graphql/client.rb', line 32

def operation_name
  if op = @_nodes.find { |d| d.is_a?(GraphQL::Language::Nodes::OperationDefinition) }
    op.name
  else
    nil
  end
end