Skip to content

Commit

Permalink
Merge pull request rmosolgo#1716 from swalkinshaw/revert-objects-exte…
Browse files Browse the repository at this point in the history
…nding-definition-methods-from-interfaces

Revert extending interface methods onto Objects
  • Loading branch information
Robert Mosolgo authored Jul 30, 2018
2 parents 6f3b237 + 4c7e5eb commit 9896398
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
6 changes: 0 additions & 6 deletions lib/graphql/schema/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ def included(child_class)
child_class.extend(child_class::DefinitionMethods)
end
elsif child_class < GraphQL::Schema::Object
# Add all definition methods of this interface and the interfaces it
# includes onto the child class.
(interfaces + [self] - [GraphQL::Schema::Interface]).each do |interface_defn|
child_class.extend(interface_defn::DefinitionMethods)
end

# This is being included into an object type, make sure it's using `implements(...)`
backtrace_line = caller(0, 10).find { |line| line.include?("schema/object.rb") && line.include?("in `implements'")}
if !backtrace_line
Expand Down
20 changes: 2 additions & 18 deletions spec/graphql/schema/interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,6 @@ module InterfaceE
include InterfaceD
end

class ObjectA < GraphQL::Schema::Object
implements InterfaceA
end

class ObjectB < GraphQL::Schema::Object
implements InterfaceD
end

it "doesn't overwrite them when including multiple interfaces" do
def_methods = InterfaceC::DefinitionMethods

Expand All @@ -210,16 +202,8 @@ class ObjectB < GraphQL::Schema::Object
assert_equal(InterfaceC::DefinitionMethods, def_methods)
end

it "extends classes with the defined methods" do
assert_equal(ObjectA.some_method, InterfaceA.some_method)
end

it "follows the normal Ruby inheritance chain for objects implementing interfaces" do
assert_equal(ObjectB.some_method, InterfaceD.some_method)
end

it "follows the normal Ruby inheritance chain interfaces including other interfaces" do
assert_equal(InterfaceD.some_method, InterfaceE.some_method)
it "follows the normal Ruby ancestor chain when including other interfaces" do
assert_equal('not 42', InterfaceE.some_method)
end
end
end
24 changes: 0 additions & 24 deletions spec/graphql/schema/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,6 @@
assert_equal object_class.description, new_subclass_2.description
end

it "does not inherit singleton methods from base interface when implementing base interface" do
object_type = Class.new(GraphQL::Schema::Object)
methods = object_type.singleton_methods
method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]

object_type.implements(GraphQL::Schema::Interface)
new_method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
assert_equal method_defs, new_method_defs
end

it "does not inherit singleton methods from base interface when implementing another interface" do
object_type = Class.new(GraphQL::Schema::Object)
methods = object_type.singleton_methods
method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]

module InterfaceType
include GraphQL::Schema::Interface
end

object_type.implements(InterfaceType)
new_method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
assert_equal method_defs, new_method_defs
end

it "should take Ruby name (without Type suffix) as default graphql name" do
TestingClassType = Class.new(GraphQL::Schema::Object)
assert_equal "TestingClass", TestingClassType.graphql_name
Expand Down

0 comments on commit 9896398

Please sign in to comment.