Class: GraphQL::Rubocop::GraphQL::DefaultRequiredTrue

Inherits:
BaseCop
  • Object
show all
Defined in:
lib/graphql/rubocop/graphql/default_required_true.rb

Overview

Identify (and auto-correct) any argument configuration which duplicates the default required: true property.

required: true is default because required arguments can always be converted to optional arguments (required: false) without a breaking change. (The opposite change, from required: false to required: true, change.)

Examples:

# Both of these define `id: ID!` in GraphQL:

# bad
argument :id, ID, required: true

# good
argument :id, ID

Constant Summary collapse

MSG =
"`required: true` is the default and can be removed."

Instance Method Summary collapse

Methods inherited from BaseCop

#source_without_keyword_argument

Instance Method Details

#on_send(node) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/graphql/rubocop/graphql/default_required_true.rb', line 32

def on_send(node)
  argument_config_with_required_true?(node) do |required_config|
    add_offense(required_config) do |corrector|
      cleaned_node_source = source_without_keyword_argument(node, required_config)
      corrector.replace(node, cleaned_node_source)
    end
  end
end