Class: RuboCop::GraphQL::Argument
- Inherits:
-
Object
- Object
- RuboCop::GraphQL::Argument
- Extended by:
- NodePattern::Macros
- Defined in:
- lib/rubocop/graphql/argument.rb,
lib/rubocop/graphql/argument/block.rb,
lib/rubocop/graphql/argument/kwargs.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #argument_as(node) ⇒ Object
- #argument_description(node) ⇒ Object
- #argument_name(node) ⇒ Object
- #argument_required(node) ⇒ Object
- #as ⇒ Object
- #block ⇒ Object
-
#default_value? ⇒ Boolean
A configured default is always passed, even when the client omits the argument.
- #description ⇒ Object
-
#initialize(node) ⇒ Argument
constructor
A new instance of Argument.
-
#keyword ⇒ Object
The keyword this argument is passed as to #resolve and friends.
- #kwargs ⇒ Object
- #name ⇒ Object
-
#optional? ⇒ Boolean
required: falseis the only value that lets graphql-ruby omit the keyword:required: :nullablestill demands the argument be present, though it may be null.
Constructor Details
#initialize(node) ⇒ Argument
Returns a new instance of Argument.
30 31 32 |
# File 'lib/rubocop/graphql/argument.rb', line 30 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
28 29 30 |
# File 'lib/rubocop/graphql/argument.rb', line 28 def node @node end |
Instance Method Details
#argument_as(node) ⇒ Object
19 20 21 |
# File 'lib/rubocop/graphql/argument.rb', line 19 def_node_matcher :argument_as, "(pair (sym :as) (sym $_))\n" |
#argument_description(node) ⇒ Object
9 10 11 |
# File 'lib/rubocop/graphql/argument.rb', line 9 def_node_matcher :argument_description, "(send nil? :argument _ _ (:str $_) ...)\n" |
#argument_name(node) ⇒ Object
14 15 16 |
# File 'lib/rubocop/graphql/argument.rb', line 14 def_node_matcher :argument_name, "(send nil? :argument (:sym $_) ...)\n" |
#argument_required(node) ⇒ Object
24 25 26 |
# File 'lib/rubocop/graphql/argument.rb', line 24 def_node_matcher :argument_required, "(pair (sym :required) $_)\n" |
#as ⇒ Object
38 39 40 |
# File 'lib/rubocop/graphql/argument.rb', line 38 def as @as ||= argument_as(kwargs.as) end |
#block ⇒ Object
73 74 75 |
# File 'lib/rubocop/graphql/argument.rb', line 73 def block @block ||= Argument::Block.new(@node.parent) end |
#default_value? ⇒ Boolean
A configured default is always passed, even when the client omits the argument.
61 62 63 |
# File 'lib/rubocop/graphql/argument.rb', line 61 def default_value? !kwargs.default_value.nil? end |
#description ⇒ Object
65 66 67 |
# File 'lib/rubocop/graphql/argument.rb', line 65 def description @description ||= argument_description(@node) || kwargs.description || block.description end |
#keyword ⇒ Object
The keyword this argument is passed as to #resolve and friends. as: wins when both
are given, matching graphql-ruby's kwargs[:as] ||= inferred_arg_name.
44 45 46 47 48 49 |
# File 'lib/rubocop/graphql/argument.rb', line 44 def keyword return as if kwargs.as return inferred_keyword if kwargs.loads name end |
#kwargs ⇒ Object
69 70 71 |
# File 'lib/rubocop/graphql/argument.rb', line 69 def kwargs @kwargs ||= Argument::Kwargs.new(@node) end |
#name ⇒ Object
34 35 36 |
# File 'lib/rubocop/graphql/argument.rb', line 34 def name @name ||= argument_name(@node) end |
#optional? ⇒ Boolean
required: false is the only value that lets graphql-ruby omit the keyword:
required: :nullable still demands the argument be present, though it may be null.
53 54 55 56 57 58 |
# File 'lib/rubocop/graphql/argument.rb', line 53 def optional? required_node = kwargs.required return false unless required_node argument_required(required_node)&.false_type? || false end |