lib/graphql/schema/interface.rb in graphql-1.8.0.pre9 vs lib/graphql/schema/interface.rb in graphql-1.8.0.pre10

- old
+ new

@@ -2,20 +2,26 @@ module GraphQL class Schema class Interface < GraphQL::Schema::Member extend GraphQL::Schema::Member::HasFields extend GraphQL::Schema::Member::AcceptsDefinition - field_class GraphQL::Schema::Field class << self + # Always set up a `self::Implementation` module, + # which may or may not be added to. + def inherited(child_cls) + # This module will be mixed in to each object class, + # so it can contain methods to implement fields. + # It's always added to interfaces, but sometimes it's left empty. + child_cls.const_set(:Implementation, Module.new) + end + # When this interface is added to a `GraphQL::Schema::Object`, # it calls this method. We add methods to the object by convention, # a nested module named `Implementation` - def apply_implemented(object_class) - if defined?(self::Implementation) - object_class.include(self::Implementation) - end + def implemented(object_class) + object_class.include(self::Implementation) end def orphan_types(*types) if types.any? @orphan_types = types @@ -33,9 +39,10 @@ type_defn.orphan_types = orphan_types fields.each do |field_name, field_inst| field_defn = field_inst.graphql_definition type_defn.fields[field_defn.name] = field_defn end + type_defn.metadata[:type_class] = self if respond_to?(:resolve_type) type_defn.resolve_type = method(:resolve_type) end type_defn end