@@ -35,8 +35,14 @@ def call(query, mutation)
3535 raise ::GraphqlDevise ::Error , 'You need to provide a mutation type unless all mutations are skipped'
3636 end
3737
38- prepared_mutations . each do |action , prepared_mutation |
39- mutation . field ( action , mutation : prepared_mutation , authenticate : false )
38+ begin
39+ prepared_mutations . each do |action , prepared_mutation |
40+ mutation . field ( action , mutation : prepared_mutation , authenticate : false )
41+ end
42+ rescue ArgumentError
43+ raise unless Gem ::Version . new ( GraphQL ::VERSION ) >= Gem ::Version . new ( '2.0' )
44+
45+ raise_undefined_field_class_error ( 'MutationType' )
4046 end
4147
4248 prepared_resolvers = prepare_resolvers ( @resource , clean_options , authenticatable_type )
@@ -45,8 +51,14 @@ def call(query, mutation)
4551 raise ::GraphqlDevise ::Error , 'You need to provide a query type unless all queries are skipped'
4652 end
4753
48- prepared_resolvers . each do |action , resolver |
49- query . field ( action , resolver : resolver , authenticate : false )
54+ begin
55+ prepared_resolvers . each do |action , resolver |
56+ query . field ( action , resolver : resolver , authenticate : false )
57+ end
58+ rescue ArgumentError
59+ raise unless Gem ::Version . new ( GraphQL ::VERSION ) >= Gem ::Version . new ( '2.0' )
60+
61+ raise_undefined_field_class_error ( 'QueryType' )
5062 end
5163
5264 ::GraphqlDevise . add_mapping ( ::GraphqlDevise . to_mapping_name ( @resource ) . to_sym , @resource )
@@ -57,6 +69,35 @@ def call(query, mutation)
5769
5870 private
5971
72+ def raise_undefined_field_class_error ( type_class )
73+ raise (
74+ GraphqlDevise ::Error ,
75+ <<~MESSAGE
76+ To use this gem with graphql >= 2.0 you need to use a custom `field_class`
77+ on your #{ type_class } . You can use the `field_class` defined in this gem like this:
78+
79+ module Types
80+ class #{ type_class } < GraphQL::Schema::Object
81+ field_class GraphqlDevise::Types::BaseField
82+ end
83+ end
84+
85+ If you already have a `field_class` set on your #{ type_class } , you can include our concern
86+ to make this work
87+
88+ module Types
89+ class BaseField < GraphQL::Schema::Field
90+ include GraphqlDevise::FieldAuthentication
91+ end
92+ end
93+
94+ The concern will define an initializer, if your custom field logic is not standard, you can look
95+ at the `GraphqlDevise::FieldAuthentication` implementation to add what is required to your own
96+ field class
97+ MESSAGE
98+ )
99+ end
100+
60101 def prepare_resolvers ( model , clean_options , authenticatable_type )
61102 MountMethod ::OperationPreparer . new (
62103 model : model ,
0 commit comments