@@ -3,6 +3,11 @@ class Mapper
33 def mount_graphql_devise_for ( resource , opts = { } )
44 custom_operations = opts [ :operations ] || { }
55 skipped_operations = opts . fetch ( :skip , [ ] )
6+ only_operations = opts . fetch ( :only , [ ] )
7+
8+ if [ skipped_operations , only_operations ] . all? ( &:any? )
9+ raise GraphqlDevise ::Error , "Can't specify both `skip` and `only` options when mounting the route."
10+ end
611
712 default_mutations = {
813 login : GraphqlDevise ::Mutations ::Login ,
@@ -20,6 +25,9 @@ def mount_graphql_devise_for(resource, opts = {})
2025 unless skipped_operations . all? { |skipped | supported_operations . include? ( skipped ) }
2126 raise GraphqlDevise ::Error , 'Trying to skip a non supported operation. Check for typos.'
2227 end
28+ unless only_operations . all? { |only | supported_operations . include? ( only ) }
29+ raise GraphqlDevise ::Error , 'One of the `only` operations is not supported. Check for typos.'
30+ end
2331
2432 path = opts . fetch ( :at , '/graphql_auth' )
2533 mapping_name = resource . underscore . tr ( '/' , '_' ) . to_sym
@@ -34,7 +42,12 @@ def mount_graphql_devise_for(resource, opts = {})
3442 "Types::#{ resource } Type" . safe_constantize ||
3543 GraphqlDevise ::Types ::AuthenticableType
3644
37- default_mutations . except ( *skipped_operations ) . each do |action , mutation |
45+ used_mutations = if only_operations . present?
46+ default_mutations . slice ( *only_operations )
47+ else
48+ default_mutations . except ( *skipped_operations )
49+ end
50+ used_mutations . each do |action , mutation |
3851 used_mutation = if custom_operations [ action ] . present?
3952 custom_operations [ action ]
4053 else
@@ -49,7 +62,12 @@ def mount_graphql_devise_for(resource, opts = {})
4962 GraphqlDevise ::Types ::MutationType . field ( "#{ mapping_name } _#{ action } " , mutation : used_mutation )
5063 end
5164
52- default_queries . except ( *skipped_operations ) . each do |action , query |
65+ used_queries = if only_operations . present?
66+ default_queries . slice ( *only_operations )
67+ else
68+ default_queries . except ( *skipped_operations )
69+ end
70+ used_queries . each do |action , query |
5371 used_query = if custom_operations [ action ] . present?
5472 custom_operations [ action ]
5573 else
0 commit comments