Sha256: 7288fc5505c7449c7058f398b45863713524bf615aecbbf76522ae090690231a

Contents?: true

Size: 838 Bytes

Versions: 13

Compression:

Stored size: 838 Bytes

Contents

module GraphQL
  module StaticValidation
    class FragmentTypesExist
      include GraphQL::StaticValidation::Message::MessageHelper

      FRAGMENTS_ON_TYPES = [
        GraphQL::Language::Nodes::FragmentDefinition,
        GraphQL::Language::Nodes::InlineFragment,
      ]

      def validate(context)
        FRAGMENTS_ON_TYPES.each do |node_class|
          context.visitor[node_class] << -> (node, parent) { validate_type_exists(node, context) }
        end
      end

      private

      def validate_type_exists(node, context)
        return unless node.type
        type = context.schema.types.fetch(node.type, nil)
        if type.nil?
          context.errors << message("No such type #{node.type}, so it can't be a fragment condition", node)
          GraphQL::Language::Visitor::SKIP
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-0.17.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.17.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.17.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.16.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.16.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.15.3 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.15.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.14.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.15.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.15.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.14.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.14.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.13.0 lib/graphql/static_validation/rules/fragment_types_exist.rb