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

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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/graphql/stitching/type_resolver.rb', line 28

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.



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

def arguments
  @arguments
end

#fieldObject (readonly)

name of the root field to query.



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

def field
  @field
end

#keyObject (readonly)

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



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

def key
  @key
end

#locationObject (readonly)

location name providing the resolver query.



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

def location
  @location
end

#type_nameObject (readonly)

name of merged type fulfilled through this resolver.



17
18
19
# File 'lib/graphql/stitching/type_resolver.rb', line 17

def type_name
  @type_name
end

Instance Method Details

#==(other) ⇒ Object



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

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

#as_jsonObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/graphql/stitching/type_resolver.rb', line 57

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

#list?Boolean

specifies when the resolver is a list query.

Returns:

  • (Boolean)


45
46
47
# File 'lib/graphql/stitching/type_resolver.rb', line 45

def list?
  @list
end

#versionObject



49
50
51
# File 'lib/graphql/stitching/type_resolver.rb', line 49

def version
  @version ||= Stitching.digest.call("#{Stitching::VERSION}/#{as_json.to_json}")
end