Sha256: 1f568a85a24212eeacdea8bfe7efddcc5d3a10fa3e65a5098432d9802ebd7bac
Contents?: true
Size: 1.13 KB
Versions: 47
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true module GraphQL module StaticValidation class FieldsAreDefinedOnType include GraphQL::StaticValidation::Message::MessageHelper def validate(context) visitor = context.visitor visitor[GraphQL::Language::Nodes::Field] << ->(node, parent) { parent_type = context.object_types[-2] parent_type = parent_type.unwrap validate_field(context, node, parent_type, parent) } end private def validate_field(context, ast_field, parent_type, parent) if parent_type.kind.union? && ast_field.name != '__typename' context.errors << message("Selections can't be made directly on unions (see selections on #{parent_type.name})", parent, context: context) return GraphQL::Language::Visitor::SKIP end field = context.warden.get_field(parent_type, ast_field.name) if field.nil? context.errors << message("Field '#{ast_field.name}' doesn't exist on type '#{parent_type.name}'", ast_field, context: context) return GraphQL::Language::Visitor::SKIP end end end end end
Version data entries
47 entries across 47 versions & 1 rubygems