Sha256: 8c78e6b0ce9540e4e77c3cdc93f0e063eb9e43b107536c34dec6e019b7d20598
Contents?: true
Size: 890 Bytes
Versions: 1
Compression:
Stored size: 890 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_name = node.type.name type = context.schema.types.fetch(type_name, nil) if type.nil? context.errors << message("No such type #{type_name}, so it can't be a fragment condition", node, context: context) GraphQL::Language::Visitor::SKIP end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
graphql-1.0.0 | lib/graphql/static_validation/rules/fragment_types_exist.rb |