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.
-
#interface_implementers(ctx, type_defn) ⇒ Object
-
#possible_types(type_defn, ctx) ⇒ Object
Constructor Details
#initialize(schema) ⇒ PossibleTypes
Returns a new instance of PossibleTypes.
15 16 17 18 19 20 21 22 |
# File 'lib/graphql/schema/possible_types.rb', line 15 def initialize(schema) @object_types = schema.types.values.select { |type| type.kind.object? } @interface_implementers = Hash.new do |h1, ctx| h1[ctx] = Hash.new do |h2, int_type| h2[int_type] = @object_types.select { |type| type.interfaces(ctx).include?(int_type) }.sort_by(&:name) end end end |
Instance Method Details
#interface_implementers(ctx, type_defn) ⇒ Object
39 40 41 |
# File 'lib/graphql/schema/possible_types.rb', line 39 def interface_implementers(ctx, type_defn) @interface_implementers[ctx][type_defn] end |
#possible_types(type_defn, ctx) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/graphql/schema/possible_types.rb', line 24 def possible_types(type_defn, ctx) case type_defn when Module possible_types(type_defn.graphql_definition, ctx) when GraphQL::UnionType type_defn.possible_types(ctx) when GraphQL::InterfaceType interface_implementers(ctx, type_defn) when GraphQL::BaseType [type_defn] else raise "Unexpected possible_types object: #{type_defn.inspect}" end end |