Sha256: 114843a2880eccbbe6be1024f63abc105fec54856d8de09c1b0e8c9ad6cacb7c

Contents?: true

Size: 969 Bytes

Versions: 20

Compression:

Stored size: 969 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, context: context)
          GraphQL::Language::Visitor::SKIP
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql-0.19.3 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.19.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.19.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.19.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.15 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.14 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.13 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.12 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.11 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.10 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.9 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.8 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.7 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.6 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.5 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.4 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.3 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-0.18.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb