Skip to content

Commit 1c92184

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#3325 from splattael/fix-prepended-modules
Allow types to be prepended by a module
2 parents 0b3380b + 6ef8955 commit 1c92184

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lib/graphql/schema/find_inherited_value.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def find_inherited_value(method_name, default_value = nil)
2020
if self.is_a?(Class)
2121
superclass.respond_to?(method_name, true) ? superclass.send(method_name) : default_value
2222
else
23-
ancestors[1..-1].each do |ancestor|
23+
ancestors_except_self = ancestors
24+
ancestors_except_self.delete(self)
25+
ancestors_except_self.each do |ancestor|
2426
if ancestor.respond_to?(method_name, true)
2527
return ancestor.send(method_name)
2628
end

lib/graphql/schema/member/has_fields.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ def field_class(new_field_class = nil)
7474
@field_class = new_field_class
7575
elsif defined?(@field_class) && @field_class
7676
@field_class
77-
elsif self.is_a?(Class)
78-
superclass.respond_to?(:field_class) ? superclass.field_class : GraphQL::Schema::Field
7977
else
80-
ancestor = ancestors[1..-1].find { |a| a.respond_to?(:field_class) && a.field_class }
81-
ancestor ? ancestor.field_class : GraphQL::Schema::Field
78+
find_inherited_value(:field_class, GraphQL::Schema::Field)
8279
end
8380
end
8481

spec/support/jazz.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,15 @@ def self.find(id)
167167
end
168168
end
169169

170+
module WithNameField
171+
def self.prepended(base)
172+
base.field :name, String, null: false
173+
end
174+
end
175+
170176
module NamedEntity
171177
include BaseInterface
172-
field :name, String, null: false
178+
prepend WithNameField
173179
end
174180

175181
class PrivateMembership < GraphQL::Schema::TypeMembership

0 commit comments

Comments
 (0)