11module ActionDispatch ::Routing
22 class Mapper
33 def mount_graphql_devise_for ( resource , opts = { } )
4- custom_operations = opts [ :operations ] || { }
5- skipped_operations = opts . fetch ( :skip , [ ] )
6- only_operations = opts . fetch ( :only , [ ] )
4+ custom_operations = opts . fetch ( :operations , { } )
5+ skipped_operations = opts . fetch ( :skip , [ ] )
6+ only_operations = opts . fetch ( :only , [ ] )
7+ additional_mutations = opts . fetch ( :additional_mutations , { } )
8+ additional_queries = opts . fetch ( :additional_queries , { } )
79
810 if [ skipped_operations , only_operations ] . all? ( &:any? )
911 raise GraphqlDevise ::Error , "Can't specify both `skip` and `only` options when mounting the route."
@@ -62,8 +64,11 @@ def mount_graphql_devise_for(resource, opts = {})
6264
6365 GraphqlDevise ::Types ::MutationType . field ( "#{ mapping_name } _#{ action } " , mutation : used_mutation )
6466 end
67+ additional_mutations . each do |action , mutation |
68+ GraphqlDevise ::Types ::MutationType . field ( action , mutation : mutation )
69+ end
6570
66- if used_mutations . present? &&
71+ if ( used_mutations . present? || additional_mutations . present? ) &&
6772 ( Gem ::Version . new ( GraphQL ::VERSION ) <= Gem ::Version . new ( '1.10.0' ) || GraphqlDevise ::Schema . mutation . nil? )
6873 GraphqlDevise ::Schema . mutation ( GraphqlDevise ::Types ::MutationType )
6974 end
@@ -87,8 +92,11 @@ def mount_graphql_devise_for(resource, opts = {})
8792
8893 GraphqlDevise ::Types ::QueryType . field ( "#{ mapping_name } _#{ action } " , resolver : used_query )
8994 end
95+ additional_queries . each do |action , resolver |
96+ GraphqlDevise ::Types ::QueryType . field ( action , resolver : resolver )
97+ end
9098
91- if used_queries . blank? && GraphqlDevise ::Types ::QueryType . fields . blank?
99+ if ( used_queries . blank? || additional_queries . present? ) && GraphqlDevise ::Types ::QueryType . fields . blank?
92100 GraphqlDevise ::Types ::QueryType . field ( :dummy , resolver : GraphqlDevise ::Resolvers ::Dummy )
93101 end
94102
0 commit comments