Class: GraphQL::Stitching::Resolver::KeyArgumentValue Private

Inherits:
ArgumentValue
  • Object
show all
Defined in:
lib/graphql/stitching/resolver/arguments.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 key input value

Instance Attribute Summary

Attributes inherited from ArgumentValue

#value

Instance Method Summary collapse

Methods inherited from ArgumentValue

#==

Constructor Details

#initialize(value) ⇒ KeyArgumentValue

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 KeyArgumentValue.

[View source]

123
124
125
# File 'lib/graphql/stitching/resolver/arguments.rb', line 123

def initialize(value)
  super(Array(value))
end

Instance Method Details

#build(origin_obj) ⇒ 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.

[View source]

147
148
149
150
151
# File 'lib/graphql/stitching/resolver/arguments.rb', line 147

def build(origin_obj)
  value.each_with_index.reduce(origin_obj) do |obj, (ns, idx)|
    obj[idx.zero? ? Resolver.export_key(ns) : ns]
  end
end

#key?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:

  • (Boolean)
[View source]

127
128
129
# File 'lib/graphql/stitching/resolver/arguments.rb', line 127

def key?
  true
end

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.

[View source]

153
154
155
# File 'lib/graphql/stitching/resolver/arguments.rb', line 153

def print
  "$.#{value.join(".")}"
end

#verify_key(arg, key) ⇒ 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.

[View source]

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/graphql/stitching/resolver/arguments.rb', line 131

def verify_key(arg, key)
  key_field = value.reduce(Resolver::KeyField.new("", inner: key)) do |field, ns|
    if ns == Resolver::TYPE_NAME
      Resolver::KeyField.new(Resolver::TYPE_NAME)
    elsif field
      field.inner.find { _1.name == ns }
    end
  end

  # still not capturing enough type information to accurately compare key/arg types...
  # best we can do for now is to verify the argument insertion matches a key path.
  if key_field.nil?
    raise CompositionError, "Argument `#{arg.name}: #{print}` cannot insert key `#{key.to_definition}`."
  end
end