Class: Gitlab::Graphql::KnownOperations

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/graphql/known_operations.rb

Defined Under Namespace

Classes: Operation

Constant Summary collapse

UNKNOWN =
Operation.new("unknown", {}).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_data) ⇒ KnownOperations

Returns a new instance of KnownOperations.



30
31
32
33
34
35
# File 'lib/gitlab/graphql/known_operations.rb', line 30

def initialize(operation_data)
  @operation_hash = operation_data
                      .map { |name, | Operation.new(name, ).freeze }
                      .concat([UNKNOWN])
                      .index_by(&:name)
end

Class Method Details

.defaultObject



26
27
28
# File 'lib/gitlab/graphql/known_operations.rb', line 26

def self.default
  @default ||= self.new(Gitlab::Webpack::GraphqlKnownOperations.load)
end

Instance Method Details

#from_query(query) ⇒ Object

Returns the known operation from the given ::GraphQL::Query object



38
39
40
41
42
43
44
# File 'lib/gitlab/graphql/known_operations.rb', line 38

def from_query(query)
  operation_name = query.selected_operation_name

  return UNKNOWN unless operation_name

  @operation_hash[operation_name] || UNKNOWN
end

#operationsObject



46
47
48
# File 'lib/gitlab/graphql/known_operations.rb', line 46

def operations
  @operation_hash.values
end