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.name` and 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_type` function 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)
61 62 63 64 65 66 67 |
# File 'lib/graphql/base_type.rb', line 61 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!
76 77 78 79 80 |
# File 'lib/graphql/base_type.rb', line 76 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
89 90 91 92 |
# File 'lib/graphql/base_type.rb', line 89 def resolve_type=(new_proc) warn_resolve_type_deprecated @resolve_type_proc = new_proc || DEFAULT_RESOLVE_TYPE end |
#warn_resolve_type_deprecated ⇒ Object
94 95 96 |
# File 'lib/graphql/base_type.rb', line 94 def warn_resolve_type_deprecated warn("#{self.name}.resolve_type is deprecated; define Schema.resolve_type instead") end |