Class: ActionPolicy::GraphQL::AuthorizedField::PreauthorizeExtension
- Inherits:
-
Extension
- Object
- GraphQL::Schema::FieldExtension
- Extension
- ActionPolicy::GraphQL::AuthorizedField::PreauthorizeExtension
- Defined in:
- lib/action_policy/graphql/authorized_field.rb
Instance Method Summary collapse
Methods inherited from Extension
Instance Method Details
#apply ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/action_policy/graphql/authorized_field.rb', line 61 def apply if [:with].nil? raise ArgumentError, "You must specify the policy for preauthorization: " \ "`field :#{field.name}, preauthorize: {with: SomePolicy}`" end @to = extract_option(:to) do if field.type.list? ::ActionPolicy::GraphQL. else ::ActionPolicy::GraphQL. end end @raise = extract_option(:raise) do if field.mutation ::ActionPolicy::GraphQL. else ::ActionPolicy::GraphQL. end end end |
#resolve(context:, object:, arguments:, **_rest) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/action_policy/graphql/authorized_field.rb', line 84 def resolve(context:, object:, arguments:, **_rest) if @raise object. field.name, to: @to, ** yield object, arguments elsif object.allowed_to?(@to, field.name, **) yield object, arguments end end |