File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -857,6 +857,17 @@ def extra_types(*new_extra_types)
857
857
def orphan_types ( *new_orphan_types )
858
858
if new_orphan_types . any?
859
859
new_orphan_types = new_orphan_types . flatten
860
+ non_object_types = new_orphan_types . reject { |ot | ot . is_a? ( Class ) && ot < GraphQL ::Schema ::Object }
861
+ if non_object_types . any?
862
+ raise ArgumentError , <<~ERR
863
+ Only object type classes should be added as `orphan_types(...)`.
864
+
865
+ - Remove these no-op types from `orphan_types`: #{ non_object_types . map ( &:inspect ) . join ( ", " ) }
866
+ - See https://graphql-ruby.org/type_definitions/interfaces.html#orphan-types
867
+
868
+ To add other types to your schema, you might want `extra_types`: https://graphql-ruby.org/schema/definition.html#extra-types
869
+ ERR
870
+ end
860
871
add_type_and_traverse ( new_orphan_types , root : false )
861
872
own_orphan_types . concat ( new_orphan_types . flatten )
862
873
end
Original file line number Diff line number Diff line change @@ -152,6 +152,26 @@ class CustomSubscriptions < GraphQL::Subscriptions::ActionCableSubscriptions
152
152
end
153
153
end
154
154
155
+ class ExampleOptionEnum < GraphQL ::Schema ::Enum
156
+ end
157
+ it "rejects non-object types to orphan_types" do
158
+ object_type = Class . new ( GraphQL ::Schema ::Object )
159
+ err = assert_raises ArgumentError do
160
+ Class . new ( GraphQL ::Schema ) do
161
+ orphan_types ( ExampleOptionEnum , object_type )
162
+ end
163
+ end
164
+
165
+ expected_msg = "Only object type classes should be added as `orphan_types(...)`.
166
+
167
+ - Remove these no-op types from `orphan_types`: ExampleOptionEnum
168
+ - See https://graphql-ruby.org/type_definitions/interfaces.html#orphan-types
169
+
170
+ To add other types to your schema, you might want `extra_types`: https://graphql-ruby.org/schema/definition.html#extra-types
171
+ "
172
+ assert_equal expected_msg , err . message
173
+ end
174
+
155
175
describe "merged, inherited caches" do
156
176
METHODS_TO_CACHE = {
157
177
types : 1 ,
Original file line number Diff line number Diff line change @@ -517,7 +517,7 @@ class Schema < GraphQL::Schema
517
517
mutation DairyAppMutation
518
518
subscription Subscription
519
519
max_depth 5
520
- orphan_types Honey , Beverage
520
+ orphan_types Honey
521
521
trace_with GraphQL ::Tracing ::CallLegacyTracers
522
522
523
523
rescue_from ( NoSuchDairyError ) { |err | raise GraphQL ::ExecutionError , err . message }
You can’t perform that action at this time.
0 commit comments