Class: RuboCop::Cop::GraphQL::FieldDescription

Inherits:
Base
  • Object
show all
Includes:
GraphQL::NodePattern
Defined in:
lib/rubocop/cop/graphql/field_description.rb

Overview

This cop checks if each field has a description.

Fields built from a resolver, mutation or subscription class are not flagged: graphql-ruby takes their description from that class.

Examples:

# good

class UserType < BaseType
  field :name, String, "Name of the user", null: true
end

# bad

class UserType < BaseType
  field :name, String, null: true
end
# good

class UserType < BaseType
  field :posts, resolver: PostsResolver
end

Constant Summary collapse

MSG =
"Missing field description"
RESTRICT_ON_SEND =
%i[field].freeze

Instance Method Summary collapse

Methods included from GraphQL::NodePattern

#argument?, #field?, #field_definition?, #field_definition_with_body?

Instance Method Details

#on_send(node) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rubocop/cop/graphql/field_description.rb', line 37

def on_send(node)
  return unless field_definition?(node)

  field = RuboCop::GraphQL::Field.new(node)
  return if field.kwargs.resolver_class

  add_offense(node) unless field.description
end