Class: RuboCop::Cop::Ezcater::RequireGqlErrorHelpers

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/ezcater/require_gql_error_helpers.rb

Overview

Enforce use of GQLErrors helpers instead of throwing GraphQL::ExecutionErrors directly

Examples:


# good
GQLErrors.summary_error("An error occurred")
GQLErrors.request_error("You can't access this", 401)
GQLErrors.field_error("is invalid", :first_name, "First Name")
GQLErrors.field_errors_for(my_model, context)
GQLErrors.field_errors_for(my_model, context, summary_error: "An error occurred")
GQLErrors.field_errors_for(my_model, context, field_mapping: { first: :first_name })

# bad
GraphQL::ExecutionError.new("An error occurred")
GraphQL::ExecutionError.new("You can't access this", options: { status_code: 401 })

Constant Summary collapse

MSG =
"Use the helpers provided by `GQLErrors` instead of raising `GraphQL::ExecutionError` directly."

Instance Method Summary collapse

Instance Method Details

#on_const(node) ⇒ Object



29
30
31
32
33
# File 'lib/rubocop/cop/ezcater/require_gql_error_helpers.rb', line 29

def on_const(node)
  return unless graphql_const?(node)

  add_offense(node, location: :expression, message: MSG)
end