Sha256: 8149fe6c63b8193909e783070b4e41f3e93ec2a789a16976fe0569c08c67333b

Contents?: true

Size: 1 KB

Versions: 173

Compression:

Stored size: 1 KB

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 = context.warden.get_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

173 entries across 173 versions & 2 rubygems

Version Path
graphql-2.2.16 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.1.13 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.7 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.6 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.5 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.0.31 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.2 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.1 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-1.13.23 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.3.0 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.14 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.13 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.12 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.0.29 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.1.12 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-1.13.22 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.11 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.10 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.9 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
graphql-2.2.8 lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb