Sha256: 330565247cca1af81f99f59c577eef65110032484e4215f0375d571861355673

Contents?: true

Size: 661 Bytes

Versions: 4

Compression:

Stored size: 661 Bytes

Contents

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

  FRAGMENTS_ON_TYPES = [
    GraphQL::Nodes::FragmentDefinition,
    GraphQL::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::Visitor::SKIP
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql-0.5.0 lib/graph_ql/static_validation/rules/fragment_types_exist.rb
graphql-0.4.0 lib/graph_ql/static_validation/rules/fragment_types_exist.rb
graphql-0.3.0 lib/graph_ql/static_validation/rules/fragment_types_exist.rb
graphql-0.2.0 lib/graph_ql/static_validation/fragment_types_exist.rb