Sha256: b85703443e8d6be210cceceaf5d39b335f7aa7fd643708d6ace9ff16fb40b05e

Contents?: true

Size: 856 Bytes

Versions: 20

Compression:

Stored size: 856 Bytes

Contents

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

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

      def validate(context)
        FRAGMENTS_ON_TYPES.each do |node_class|
          context.visitor[node_class] << -> (node, parent) { validate_type_exists(node, context) }
        end
      end

      private

      def validate_type_exists(node, context)
        return unless node.type
        type = context.schema.types.fetch(node.type, nil)
        if type.nil?
          context.errors << message("No such type #{node.type}, so it can't be a fragment condition", 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/fragment_types_exist.rb
graphql-0.19.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.19.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.19.0 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.15 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.14 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.13 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.12 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.11 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.10 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.9 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.8 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.7 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.6 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.5 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.4 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.3 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.2 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.1 lib/graphql/static_validation/rules/fragment_types_exist.rb
graphql-0.18.0 lib/graphql/static_validation/rules/fragment_types_exist.rb