Sha256: eb0124944584d83a4fb0c24b6c5e2c2bc6285f4729d6b0da98806725180efe37

Contents?: true

Size: 919 Bytes

Versions: 13

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module FragmentTypesExist
      def on_fragment_definition(node, _parent)
        if validate_type_exists(node)
          super
        end
      end

      def on_inline_fragment(node, _parent)
        if validate_type_exists(node)
          super
        end
      end

      private

      def validate_type_exists(fragment_node)
        if !fragment_node.type
          true
        else
          type_name = fragment_node.type.name
          type = @types.type(type_name)
          if type.nil?
            add_error(GraphQL::StaticValidation::FragmentTypesExistError.new(
              "No such type #{type_name}, so it can't be a fragment condition",
              nodes: fragment_node,
              type: type_name
            ))
            false
          else
            true
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-2.3.20 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.19 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.18 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.17 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.16 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.15 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.14 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.13 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.12 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.11 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.10 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.9 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-2.3.8 lib/graphql/static_validation/rules/fragment_types_exist.rb