Sha256: 859a53d3be5099751d47a4b745a5463d1afbb2976940455490ed2659d574f407

Contents?: true

Size: 951 Bytes

Versions: 13

Compression:

Stored size: 951 Bytes

Contents

module GraphQL
  module StaticValidation
    class FragmentsAreOnCompositeTypes
      include GraphQL::StaticValidation::Message::MessageHelper

      HAS_TYPE_CONDITION = [
        GraphQL::Language::Nodes::FragmentDefinition,
        GraphQL::Language::Nodes::InlineFragment,
      ]

      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

      def validate_type_is_composite(node, context)
        type_name = node.type
        return unless type_name
        type_def = context.schema.types[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)
          GraphQL::Language::Visitor::SKIP
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-0.17.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.17.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.17.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.16.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.16.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.15.3 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.15.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.14.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.15.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.15.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.14.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.14.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.13.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb