Class: GraphQL::Schema::PossibleTypes
- Inherits:
-
Object
- Object
- GraphQL::Schema::PossibleTypes
- Defined in:
- lib/graphql/schema/possible_types.rb
Overview
Find the members of a union or interface within a given schema.
(Although its members never change, unions are handled this way to simplify execution code.)
Internally, the calculation is cached. It’s assumed that schema members _don’t_ change after creating the schema!
Instance Method Summary collapse
-
#initialize(schema) ⇒ PossibleTypes
constructor
A new instance of PossibleTypes.
- #possible_types(type_defn) ⇒ Object
Constructor Details
#initialize(schema) ⇒ PossibleTypes
Returns a new instance of PossibleTypes.
14 15 16 17 18 19 20 |
# File 'lib/graphql/schema/possible_types.rb', line 14 def initialize(schema) @object_types = schema.types.values.select { |type| type.kind.object? } @storage = Hash.new do |hash, key| hash[key] = @object_types.select { |type| type.interfaces.include?(key) }.sort_by(&:name) end end |
Instance Method Details
#possible_types(type_defn) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphql/schema/possible_types.rb', line 22 def possible_types(type_defn) case type_defn when GraphQL::UnionType type_defn.possible_types when GraphQL::InterfaceType @storage[type_defn] else raise "#{type_defn} doesn't have possible types" end end |