Welcome to mirror list, hosted at ThFree Co, Russian Federation.

batch_key.rb « graphql « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 51203af5a43dcd4f47bf8f33b467d6eaa6ca7443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Gitlab
  module Graphql
    class BatchKey
      attr_reader :object
      delegate :hash, to: :object

      def initialize(object, lookahead = nil, object_name: nil)
        @object = object
        @lookahead = lookahead
        @object_name = object_name
      end

      def requires?(path)
        return false unless @lookahead
        return false unless path.present?

        field = path.pop

        path
          .reduce(@lookahead) { |q, f| q.selection(f) }
          .selects?(field)
      end

      def eql?(other)
        other.is_a?(self.class) && object == other.object
      end
      alias_method :==, :eql?

      def method_missing(method_name, *args, **kwargs)
        return @object if method_name.to_sym == @object_name
        return @object.public_send(method_name) if args.empty? && kwargs.empty? # rubocop: disable GitlabSecurity/PublicSend

        super
      end
    end
  end
end