Sha256: 0aa48df35428b852638a961f1634b1fa9e9b52c56e7fc2cc286bf19bc7068645

Contents?: true

Size: 691 Bytes

Versions: 5

Compression:

Stored size: 691 Bytes

Contents

class GraphQL::StaticValidation::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)
    type = context.schema.types[node.type]
    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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-0.7.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.7.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.6.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.6.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.6.0 lib/graphql/static_validation/rules/fragment_types_exist.rb