Class: RuboCop::Cop::Ezcater::GraphQL::NotAuthorizedScalarField
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Ezcater::GraphQL::NotAuthorizedScalarField
- Includes:
- GraphQL::NodePattern
- Defined in:
- lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb
Overview
# good
field :name, String, pundit_role: :owner
# good
field :name, String, pundit_role: :view, pundit_policy_class: "SecretNamePolicy"
Constant Summary collapse
- MSG =
"Ezcater/GraphQL/NotAuthorizedScalarFields: must be authorized."
- STANDARD_SCALAR_TYPES =
%w(BigInt Boolean Float Int ID ISO8601Date ISO8601DateTime ISO8601Duration JSON String).freeze
Instance Method Summary collapse
- #contains_resolver_method_with_guard?(node) ⇒ Object
- #field_type(node) ⇒ Object
- #field_with_body_type(node) ⇒ Object
- #field_with_guard_in_body?(node) ⇒ Object
- #field_with_pundit?(node) ⇒ Object
- #field_with_pundit_with_body?(node) ⇒ Object
- #on_class(node) ⇒ Object
Instance Method Details
#contains_resolver_method_with_guard?(node) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 135 def_node_search :contains_resolver_method_with_guard?, <<~PATTERN (def %1 (args) (block (send (send (:const ...) :new (send nil? :context) (send nil? :object)) :guard) ...) ...) PATTERN |
#field_type(node) ⇒ Object
101 102 103 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 101 def_node_matcher :field_type, <<~PATTERN (send nil? :field _ (:const nil? $_) ...) PATTERN |
#field_with_body_type(node) ⇒ Object
106 107 108 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 106 def_node_matcher :field_with_body_type, <<~PATTERN (block (send nil? :field _ (:const nil? $_) ...) ...) PATTERN |
#field_with_guard_in_body?(node) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 111 def_node_matcher :field_with_guard_in_body?, <<~PATTERN (block (send nil? :field ...) _? (block (send (send (:const ...) :new (send nil? :context) (send nil? :object)) :guard) ...) ...) PATTERN |
#field_with_pundit?(node) ⇒ Object
125 126 127 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 125 def_node_matcher :field_with_pundit?, <<~PATTERN (send nil? :field _ _ (hash <(pair (sym :pundit_role) _) ...>)) PATTERN |
#field_with_pundit_with_body?(node) ⇒ Object
130 131 132 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 130 def_node_matcher :field_with_pundit_with_body?, <<~PATTERN (block (send nil? :field _ _ (hash <(pair (sym :pundit_role) _) ...>)) ...) PATTERN |
#on_class(node) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/rubocop/cop/ezcater/graphql/not_authorized_scalar_field.rb', line 147 def on_class(node) body = RuboCop::GraphQL::SchemaMember.new(node).body each_field_node(body) do |field_node| check_field_for_offense(field_node, node) end end |