Class: GraphQL::Modernize::Rules::TypesShortcut
- Defined in:
- lib/graphql/modernize/rules/legacy.rb
Constant Summary collapse
- TYPE_DSL_CALLS =
%i[argument field input_field type].freeze
- REPLACEMENTS =
{ "Boolean" => "GraphQL::Types::Boolean", "Float" => "Float", "ID" => "GraphQL::Types::ID", "Int" => "Integer", "String" => "String" }.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#initialize, node_pattern, node_types, rule, #visit
Constructor Details
This class inherits a constructor from GraphQL::Modernize::Rules::Base
Instance Method Details
#on_match(node, _captures) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/graphql/modernize/rules/legacy.rb', line 204 def on_match(node, _captures) return unless inside?(node, :object, :input_object, :interface, :resolver, :mutation, :subscription) return if node.block || node.arguments&.arguments&.any? name = node..slice replacement = REPLACEMENTS[name] return unless replacement if @context.call_receiver?(node) return add_offense(node.location, safety: :manual, message: "Migrate chained `types.#{name}` to the class API manually") end unless type_dsl_argument?(node) return add_offense(node.location, safety: :manual, message: "Review `types.#{name}` outside the type DSL manually") end add_offense(node.location, message: "Replace `types.#{name}` with `#{replacement}`") do |rw| rw.replace(node.location, replacement) end end |