Class: GraphQL::Rubocop::GraphQL::DefaultNullTrue

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

Overview

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

null: true is default because nullable fields can always be converted to non-null fields (null: false) without a breaking change. (The opposite change, from null: false to null: true, change.)

Examples:

# Both of these define `name: String` in GraphQL:

# bad
field :name, String, null: true

# good
field :name, String

Constant Summary collapse

MSG =
"`null: 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_null_true.rb', line 32

def on_send(node)
  field_config_with_null_true?(node) do |null_config|
    add_offense(null_config) do |corrector|
      cleaned_node_source = source_without_keyword_argument(node, null_config)
      corrector.replace(node.source_range, cleaned_node_source)
    end
  end
end