Class: GraphQL::GraphQLInterfaceType
Instance Method Summary
collapse
#!
#type_of
#+@
configuration, configure_with, #method_missing, new
Constructor Details
Returns a new instance of GraphQLInterfaceType.
21
22
23
24
|
# File 'lib/graphql/type/interface_type.rb', line 21
def initialize(configuration)
super
@implementations = []
end
|
Instance Method Details
#field(name) ⇒ Object
43
44
45
|
# File 'lib/graphql/type/interface_type.rb', line 43
def field(name)
field_map(name.to_sym)
end
|
#field_map ⇒ Object
31
32
33
|
# File 'lib/graphql/type/interface_type.rb', line 31
def field_map
@field_map ||= @configuration.fields.reduce({}) { |memo, field| memo[field.name.to_sym] = field ; memo}
end
|
#field_names ⇒ Object
35
36
37
|
# File 'lib/graphql/type/interface_type.rb', line 35
def field_names
@field_names ||= field_map.keys
end
|
#fields ⇒ Object
39
40
41
|
# File 'lib/graphql/type/interface_type.rb', line 39
def fields
@fields ||= field_map.values
end
|
#implement!(type) ⇒ Object
26
27
28
29
|
# File 'lib/graphql/type/interface_type.rb', line 26
def implement!(type)
raise RuntimeError.new("#{self} can implement instances of GraphQLType. Got #{type.class}.") unless type.is_a?(GraphQLType)
@implementations << type unless possible_type?(type)
end
|
#possible_type?(type) ⇒ Boolean
51
52
53
|
# File 'lib/graphql/type/interface_type.rb', line 51
def possible_type?(type)
possible_types.include?(type)
end
|
#possible_types ⇒ Object
47
48
49
|
# File 'lib/graphql/type/interface_type.rb', line 47
def possible_types
@implementations
end
|
#resolve_type(type) ⇒ Object
55
56
57
|
# File 'lib/graphql/type/interface_type.rb', line 55
def resolve_type(type)
@configuration.resolve_type.nil? ? type_of(type) : @configuration.resolve_type.call(type)
end
|
#to_s ⇒ Object
59
60
61
|
# File 'lib/graphql/type/interface_type.rb', line 59
def to_s
name
end
|