Sha256: d6e2e079913d09070165ed7944cf23ddb119acee04d5f80fbc2fd8a8528ff030

Contents?: true

Size: 1.11 KB

Versions: 24

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
require_relative "./base_cop"

module GraphQL
  module Rubocop
    module GraphQL
      # Identify (and auto-correct) any root types in your schema file.
      #
      # @example
      #   # bad, immediately causes Rails to load `app/graphql/types/query.rb`
      #   query Types::Query
      #
      #   # good, defers loading until the file is needed
      #   query { Types::Query }
      #
      class RootTypesInBlock < BaseCop
        MSG = "type configuration can be moved to a block to defer loading the type's file"

        def_node_matcher :root_type_config_without_block, <<-Pattern
        (
          send nil? {:query :mutation :subscription} const
        )
        Pattern

        def on_send(node)
          root_type_config_without_block(node) do
            add_offense(node) do |corrector|
              new_node_source = node.source_range.source
              new_node_source.sub!(/(query|mutation|subscription)/, '\1 {')
              new_node_source << " }"
              corrector.replace(node, new_node_source)
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
graphql-2.3.22 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.3.21 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.13 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.12 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.11 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.10 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.9 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.8 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.7 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.6 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.5 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.4 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.3 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.2 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.1 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.4.0 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.3.20 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.3.19 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.3.18 lib/graphql/rubocop/graphql/root_types_in_block.rb
graphql-2.3.17 lib/graphql/rubocop/graphql/root_types_in_block.rb