Commit 1f3657dd authored by Alex Kalderimis's avatar Alex Kalderimis

Allow fields with resolvers to not have descriptions

This changes the GraphQL description cop to allow fields to have
all their metadata specified by a resolver.

Allow fields with resolvers not to have descriptions
parent 95ac4322
......@@ -54,6 +54,10 @@ module RuboCop
(send nil? :value ...)
PATTERN
def_node_matcher :resolver_kwarg, <<~PATTERN
(... (hash <(pair (sym :resolver) $_) ...>))
PATTERN
def_node_matcher :description_kwarg, <<~PATTERN
(... (hash <(pair (sym :description) $_) ...>))
PATTERN
......@@ -64,6 +68,7 @@ module RuboCop
def on_send(node)
return unless graphql_describable?(node)
return if resolver_kwarg(node) # Fields may inherit the description from their resolvers.
description = locate_description(node)
......
......@@ -6,7 +6,7 @@ require_relative '../../../../rubocop/cop/graphql/descriptions'
RSpec.describe RuboCop::Cop::Graphql::Descriptions do
subject(:cop) { described_class.new }
context 'fields' do
context 'with fields' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......@@ -46,9 +46,19 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
TYPE
end
it 'does not add an offense when there is a resolver' do
expect_no_offenses(<<~TYPE.strip)
module Types
class FakeType < BaseObject
field :a_thing, resolver: ThingResolver
end
end
TYPE
end
end
context 'arguments' do
context 'with arguments' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......@@ -90,7 +100,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
context 'enum values' do
context 'with enum values' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment