Skip to content
代码片段 群组 项目
提交 1f3657dd 编辑于 作者: 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
上级 95ac4322
No related branches found
No related tags found
无相关合并请求
...@@ -54,6 +54,10 @@ class Descriptions < RuboCop::Cop::Cop ...@@ -54,6 +54,10 @@ class Descriptions < RuboCop::Cop::Cop
(send nil? :value ...) (send nil? :value ...)
PATTERN PATTERN
def_node_matcher :resolver_kwarg, <<~PATTERN
(... (hash <(pair (sym :resolver) $_) ...>))
PATTERN
def_node_matcher :description_kwarg, <<~PATTERN def_node_matcher :description_kwarg, <<~PATTERN
(... (hash <(pair (sym :description) $_) ...>)) (... (hash <(pair (sym :description) $_) ...>))
PATTERN PATTERN
...@@ -64,6 +68,7 @@ class Descriptions < RuboCop::Cop::Cop ...@@ -64,6 +68,7 @@ class Descriptions < RuboCop::Cop::Cop
def on_send(node) def on_send(node)
return unless graphql_describable?(node) return unless graphql_describable?(node)
return if resolver_kwarg(node) # Fields may inherit the description from their resolvers.
description = locate_description(node) description = locate_description(node)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
RSpec.describe RuboCop::Cop::Graphql::Descriptions do RSpec.describe RuboCop::Cop::Graphql::Descriptions do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
context 'fields' do context 'with fields' do
it 'adds an offense when there is no description' do it 'adds an offense when there is no description' do
expect_offense(<<~TYPE) expect_offense(<<~TYPE)
module Types module Types
...@@ -46,9 +46,19 @@ class FakeType < BaseObject ...@@ -46,9 +46,19 @@ class FakeType < BaseObject
end end
TYPE TYPE
end 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 end
context 'arguments' do context 'with arguments' do
it 'adds an offense when there is no description' do it 'adds an offense when there is no description' do
expect_offense(<<~TYPE) expect_offense(<<~TYPE)
module Types module Types
...@@ -90,7 +100,7 @@ class FakeType < BaseObject ...@@ -90,7 +100,7 @@ class FakeType < BaseObject
end end
end end
context 'enum values' do context 'with enum values' do
it 'adds an offense when there is no description' do it 'adds an offense when there is no description' do
expect_offense(<<~TYPE) expect_offense(<<~TYPE)
module Types module Types
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册