Class: RuboCop::Cop::Mable::NoPostInGraphQL

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/mable/no_post_in_graph_ql.rb

Overview

Enforces using a direct helper method over ‘post` for executing GraphQL queries, incorporating user authentication context when applicable.

Examples:


# bad
post graphql_path, params: { query: my_query, variables: my_variables }, as: :json

# good
execute_graphql(query: my_query, variables: my_variables, user: current_user)

Constant Summary collapse

MSG =
"Use 'ReplacePostWith' default: `make_graphql_request` directly instead of `post` for GraphQL requests, incorporating user context."
RESTRICT_ON_SEND =
i[post].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



50
51
52
53
54
# File 'lib/rubocop/cop/mable/no_post_in_graph_ql.rb', line 50

def on_send(node)
  post_graphql?(node) do |path|
    handle_post_graphql(node) if graphql_path_allowed?(path)
  end
end