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_names) ⇒ KnownOperations

Returns a new instance of KnownOperations.


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

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

Class Method Details

.defaultObject


19
20
21
# File 'lib/gitlab/graphql/known_operations.rb', line 19

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


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

def from_query(query)
  operation_name = query.selected_operation_name

  return UNKNOWN unless operation_name

  @operation_hash[operation_name] || UNKNOWN
end

#operationsObject


39
40
41
# File 'lib/gitlab/graphql/known_operations.rb', line 39

def operations
  @operation_hash.values
end