Sha256: f0900c6aa5065dd326ccb33c4d3774da6f980b7455b4378f3ff6219e2f8a19c1

Contents?: true

Size: 702 Bytes

Versions: 20

Compression:

Stored size: 702 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.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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql-0.12.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.12.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.11.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.11.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.9 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.8 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.7 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.6 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.5 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.4 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.3 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.10.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.9.5 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.9.4 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.9.3 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.9.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.8.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.8.0 lib/graphql/static_validation/rules/fragment_types_exist.rb