class GraphQL::StaticValidation::FragmentsAreOnCompositeTypes
Constants
- HAS_TYPE_CONDITION
Public Instance Methods
validate(context)
click to toggle source
# File lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb, line 12 def validate(context) HAS_TYPE_CONDITION.each do |node_class| context.visitor[node_class] << ->(node, parent) { validate_type_is_composite(node, context) } end end
Private Instance Methods
validate_type_is_composite(node, context)
click to toggle source
# File lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb, line 22 def validate_type_is_composite(node, context) node_type = node.type if node_type.nil? # Inline fragment on the same type else type_name = node_type.to_query_string type_def = context.warden.get_type(type_name) if type_def.nil? || !type_def.kind.composite? context.errors << message("Invalid fragment on type #{type_name} (must be Union, Interface or Object)", node, context: context) GraphQL::Language::Visitor::SKIP end end end