class GraphQL::Rubocop::GraphQL::FieldTypeInBlock
Identify (and auto-correct) any field whose type configuration isn’t given in the configuration block.
Examples
Example: # bad, immediately causes Rails to load app/graphql/types/thing.rb
field :thing, Types::Thing # good, defers loading until the file is needed field :thing do type(Types::Thing) end
Constants
- BUILT_IN_SCALAR_NAMES
- MSG
Public Instance Methods
Source
# File lib/graphql/rubocop/graphql/field_type_in_block.rb, line 43 def on_block(node) ignore_node(node) field_config_with_inline_type_and_block(node) do |type_const| type_const_str = get_type_argument_str(node, type_const) if ignore_inline_type_str?(type_const_str) # Do nothing ... else add_offense(type_const) do |corrector| cleaned_node_source = delete_type_argument(node, type_const) field_indent = determine_field_indent(node) cleaned_node_source.sub!(/(\{|do)/, "\\1\n#{field_indent} type #{type_const_str}") corrector.replace(node, cleaned_node_source) end end end end
Source
# File lib/graphql/rubocop/graphql/field_type_in_block.rb, line 60 def on_send(node) return if part_of_ignored_node?(node) field_config_with_inline_type(node) do |type_const| type_const_str = get_type_argument_str(node, type_const) if ignore_inline_type_str?(type_const_str) # Do nothing -- not loading from another file else add_offense(type_const) do |corrector| cleaned_node_source = delete_type_argument(node, type_const) field_indent = determine_field_indent(node) cleaned_node_source += " do\n#{field_indent} type #{type_const_str}\n#{field_indent}end" corrector.replace(node, cleaned_node_source) end end end end