lib/graphql/schema/interface.rb
# Here's the tricky part. Make sure behavior keeps making its way down the inheritance chain.
Here's the tricky part. Make sure behavior keeps making its way down the inheritance chain.
Here ' s the tricky part . Make sure behavior keeps making its way down the inheritance chain .
def included(child_class)
          if !child_class.is_a?(Class)
            child_class.extend(Schema::Interface::DefinitionMethods)
            child_class.own_interfaces << self
            child_class.interfaces.reverse_each do |interface_defn|
              child_class.extend(interface_defn::DefinitionMethods)
            end
            if !child_class.instance_variable_defined?(:@_definition_methods)
              defn_methods_module = Module.new
              child_class.instance_variable_set(:@_definition_methods, defn_methods_module)
              child_class.const_set(:DefinitionMethods, defn_methods_module)
              child_class.extend(child_class::DefinitionMethods)
            end
          elsif child_class < GraphQL::Schema::Object
            backtrace_line = caller(0, 10).find { |line| line.include?("schema/object.rb") && line.include?("in `implements'")}
            if !backtrace_line
              raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`"
            end
          end
          super
        end
def included ( child_class ) if ! child_class . is_a? ( Class ) child_class . extend ( Schema :: Interface :: DefinitionMethods ) child_class . own_interfaces << self child_class . interfaces . reverse_each do | interface_defn | child_class . extend ( interface_defn :: DefinitionMethods ) end if ! child_class . instance_variable_defined? ( :@_definition_methods ) defn_methods_module = Module . new child_class . instance_variable_set ( :@_definition_methods , defn_methods_module ) child_class . const_set ( :DefinitionMethods , defn_methods_module ) child_class . extend ( child_class :: DefinitionMethods ) end elsif child_class < GraphQL :: Schema :: Object backtrace_line = caller ( 0 , 10 ) . find { | line | line . include? ( "schema/object.rb" ) && line . include? ( "in `implements'" ) } if ! backtrace_line raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`" end end super end
Here's the tricky part.
Here ' s the tricky part .
# In this case, it's been included into another interface. # This is how interface inheritance is implemented # We need this before we can call `own_interfaces` # Use an instance variable to tell whether it's been included previously or not; # You can't use constant detection because constants are brought into scope # by `include`, which has already happened at this point. # This is being included into an object type, make sure it's using `implements(...)`
child_class