Module: GraphQL::BaseType::HasPossibleTypes
- Included in:
- InterfaceType, UnionType
- Defined in:
- lib/graphql/base_type.rb
Constant Summary collapse
- DEFAULT_RESOLVE_TYPE =
The default implementation of #resolve_type gets
object.class.nameand finds a type with the same name -> (object, ctx) { type_name = object.class.name ctx.schema.possible_types(self).find {|t| t.name == type_name} }
Instance Method Summary collapse
-
#legacy_resolve_type(object, ctx) ⇒ Object
If a (deprecated)
resolve_typefunction was provided, call that and warn. -
#resolve_type(object, ctx) ⇒ GraphQL::ObjectType
Return the implementing type for
object. - #resolve_type=(new_proc) ⇒ Object
- #warn_resolve_type_deprecated ⇒ Object
Instance Method Details
#legacy_resolve_type(object, ctx) ⇒ Object
If a (deprecated) resolve_type function was provided, call that and warn. Otherwise call schema.resolve_type (the proper behavior)
55 56 57 58 59 60 61 |
# File 'lib/graphql/base_type.rb', line 55 def legacy_resolve_type(object, ctx) if @resolve_type_proc resolve_type(object, ctx) else ctx.schema.resolve_type(object, ctx) end end |
#resolve_type(object, ctx) ⇒ GraphQL::ObjectType
Return the implementing type for object. The default implementation assumes that there’s a type with the same name as object.class.name. Maybe you’ll need to override this in your own interfaces!
70 71 72 73 74 |
# File 'lib/graphql/base_type.rb', line 70 def resolve_type(object, ctx) ensure_defined warn_resolve_type_deprecated instance_exec(object, ctx, &(@resolve_type_proc || DEFAULT_RESOLVE_TYPE)) end |
#resolve_type=(new_proc) ⇒ Object
83 84 85 86 |
# File 'lib/graphql/base_type.rb', line 83 def resolve_type=(new_proc) warn_resolve_type_deprecated @resolve_type_proc = new_proc || DEFAULT_RESOLVE_TYPE end |
#warn_resolve_type_deprecated ⇒ Object
88 89 90 |
# File 'lib/graphql/base_type.rb', line 88 def warn_resolve_type_deprecated warn("#{self.name}.resolve_type is deprecated; define Schema.resolve_type instead") end |