Sha256: e6ebe9f346d06d73418860eec9f2854fc9a88799b402b3a10f4b22262017e644

Contents?: true

Size: 1014 Bytes

Versions: 18

Compression:

Stored size: 1014 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module FragmentsAreOnCompositeTypes
      def on_fragment_definition(node, parent)
        validate_type_is_composite(node) && super
      end

      def on_inline_fragment(node, parent)
        validate_type_is_composite(node) && super
      end

      private

      def validate_type_is_composite(node)
        node_type = node.type
        if node_type.nil?
          # Inline fragment on the same type
          true
        else
          type_name = node_type.to_query_string
          type_def = @types.type(type_name)
          if type_def.nil? || !type_def.kind.composite?
            add_error(GraphQL::StaticValidation::FragmentsAreOnCompositeTypesError.new(
              "Invalid fragment on type #{type_name} (must be Union, Interface or Object)",
              nodes: node,
              type: type_name
            ))
            false
          else
            true
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
graphql-2.4.4 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.4.3 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.4.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.4.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.4.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.20 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.19 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.18 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.17 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.16 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.15 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.14 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.13 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.12 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.11 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.10 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.9 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.8 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb