Class: Rails::GraphQL::Request::Arguments

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rails/graphql/request/arguments.rb

Overview

GraphQL Request Arguments

This is an extension of an OpenStruct since argument values can be assigned a Proc, which means that in order to collect their value, we need to rely on the current operation being processed.

They lazy variable-based value is used for fragments, so that they can be organized only once and have their variables changed accordingly to the spread and operation.

Defined Under Namespace

Classes: Lazy

Constant Summary collapse

THREAD_KEY =
:_rails_graphql_operation

Class Method Summary collapse

Class Method Details

.lazyObject

Easy access to the easy loader method



43
44
45
# File 'lib/rails/graphql/request/arguments.rb', line 43

def lazy
  Lazy
end

.operationObject

Get the current operation thread safely



48
49
50
# File 'lib/rails/graphql/request/arguments.rb', line 48

def operation
  Thread.current[THREAD_KEY]
end

.scoped(value) ⇒ Object

Execute a block inside a scoped thread-safe arguments



53
54
55
56
57
58
59
# File 'lib/rails/graphql/request/arguments.rb', line 53

def scoped(value)
  old_value, Thread.current[THREAD_KEY] = operation, value

  yield
ensure
  Thread.current[THREAD_KEY] = old_value
end

.scoped?Boolean

Check if it’s performing inside a scoped value

Returns:

  • (Boolean)


62
63
64
# File 'lib/rails/graphql/request/arguments.rb', line 62

def scoped?
  operation.present?
end