Class: GraphQL::Stitching::TypeResolver

Inherits:
Object
  • Object
show all
Extended by:
ArgumentsParser, KeysParser
Defined in:
lib/graphql/stitching/type_resolver.rb,
lib/graphql/stitching/type_resolver/keys.rb,
lib/graphql/stitching/type_resolver/arguments.rb

Overview

Defines a type resolver query that provides direct access to an entity type.

Defined Under Namespace

Modules: ArgumentsParser, KeysParser Classes: Argument, ArgumentValue, EnumArgumentValue, FieldNode, Key, KeyArgumentValue, KeyField, KeyFieldSet, LiteralArgumentValue, ObjectArgumentValue

Constant Summary collapse

EXPORT_PREFIX =
"_export_"
EMPTY_FIELD_SET =
KeyFieldSet.new(GraphQL::Stitching::EMPTY_ARRAY)
TYPENAME_EXPORT_NODE =
FieldNode.build(
  field_alias: "#{EXPORT_PREFIX}#{TYPENAME}",
  field_name: TYPENAME,
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ArgumentsParser

parse_arguments_with_field, parse_arguments_with_type_defs

Methods included from KeysParser

export_key, export_key?, parse_key, parse_key_with_types

Constructor Details

#initialize(location:, type_name: nil, list: false, field: nil, key: nil, arguments: nil) ⇒ TypeResolver

Returns a new instance of TypeResolver.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql/stitching/type_resolver.rb', line 35

def initialize(
  location:,
  type_name: nil,
  list: false,
  field: nil,
  key: nil,
  arguments: nil
)
  @location = location
  @type_name = type_name
  @list = list
  @field = field
  @key = key
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

parsed resolver Argument structures.



33
34
35
# File 'lib/graphql/stitching/type_resolver.rb', line 33

def arguments
  @arguments
end

#fieldObject (readonly)

name of the root field to query.



27
28
29
# File 'lib/graphql/stitching/type_resolver.rb', line 27

def field
  @field
end

#keyObject (readonly)

a key field to select from prior locations, sent as resolver argument.



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

def key
  @key
end

#locationObject (readonly)

location name providing the resolver query.



21
22
23
# File 'lib/graphql/stitching/type_resolver.rb', line 21

def location
  @location
end

#type_nameObject (readonly)

name of merged type fulfilled through this resolver.



24
25
26
# File 'lib/graphql/stitching/type_resolver.rb', line 24

def type_name
  @type_name
end

Class Method Details

.use_static_version?Boolean

only intended for testing...

Returns:

  • (Boolean)


15
16
17
# File 'lib/graphql/stitching/type_resolver.rb', line 15

def use_static_version?
  @use_static_version ||= false
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
# File 'lib/graphql/stitching/type_resolver.rb', line 64

def ==(other)
  self.class == other.class && self.as_json == other.as_json
end

#as_jsonObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/graphql/stitching/type_resolver.rb', line 68

def as_json
  {
    location: location,
    type_name: type_name,
    list: list?,
    field: field,
    key: key.to_definition,
    arguments: arguments.map(&:to_definition).join(", "),
    argument_types: arguments.map(&:to_type_definition).join(", "),
  }.tap(&:compact!)
end

#inspectObject



80
81
82
# File 'lib/graphql/stitching/type_resolver.rb', line 80

def inspect
  as_json.to_json
end

#list?Boolean

specifies when the resolver is a list query.

Returns:

  • (Boolean)


52
53
54
# File 'lib/graphql/stitching/type_resolver.rb', line 52

def list?
  @list
end

#versionObject



56
57
58
59
60
61
62
# File 'lib/graphql/stitching/type_resolver.rb', line 56

def version
  @version ||= if self.class.use_static_version?
    [location, field, key.to_definition, type_name].join(".")
  else
    Stitching.digest.call("#{Stitching::VERSION}/#{as_json.to_json}")
  end
end