Class: GraphQL::Execution::SelectionResult Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A set of key-value pairs suitable for a GraphQL response.

Instance Method Summary collapse

Constructor Details

#initializeSelectionResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SelectionResult.



7
8
9
10
11
# File 'lib/graphql/execution/selection_result.rb', line 7

def initialize
  @storage = {}
  @owner = nil
  @invalid_null = false
end

Instance Method Details

#delete(field_result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO this should delete by key, ya dummy



42
43
44
# File 'lib/graphql/execution/selection_result.rb', line 42

def delete(field_result)
  @storage.delete_if { |k, v| v == field_result }
end

#eachObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Visit each key-result pair in this result



26
27
28
29
30
# File 'lib/graphql/execution/selection_result.rb', line 26

def each
  @storage.each do |key, field_res|
    yield(key, field_res)
  end
end

#fetch(key) ⇒ FieldResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The result for this field.

Parameters:

  • key (String)

    The name of an already-defined result

Returns:



21
22
23
# File 'lib/graphql/execution/selection_result.rb', line 21

def fetch(key)
  @storage.fetch(key)
end

#invalid_null?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns True if this selection has been nullified by a null child.

Returns:

  • (Boolean)

    True if this selection has been nullified by a null child



57
58
59
# File 'lib/graphql/execution/selection_result.rb', line 57

def invalid_null?
  @invalid_null
end

#owner=(field_result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • field_result (FieldResult)

    The field that this selection belongs to (used for propagating nulls)



62
63
64
65
66
67
68
# File 'lib/graphql/execution/selection_result.rb', line 62

def owner=(field_result)
  if @owner
    raise("Can't change owners of SelectionResult")
  else
    @owner = field_result
  end
end

#propagate_nullObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A field has been unexpectedly nullified. Tell the owner FieldResult if it is present. Record #invalid_null in case an owner is added later.



49
50
51
52
53
54
# File 'lib/graphql/execution/selection_result.rb', line 49

def propagate_null
  if @owner
    @owner.value = GraphQL::Execution::Execute::PROPAGATE_NULL
  end
  @invalid_null = true
end

#set(key, field_result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)

    The name for this value in the result

  • field_result (FieldResult)

    The result for this field



15
16
17
# File 'lib/graphql/execution/selection_result.rb', line 15

def set(key, field_result)
  @storage[key] = field_result
end

#to_hHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A plain Hash representation of this result.

Returns:

  • (Hash)

    A plain Hash representation of this result



33
34
35
36
37
38
39
# File 'lib/graphql/execution/selection_result.rb', line 33

def to_h
  if @invalid_null
    nil
  else
    flatten(self)
  end
end