Class: GraphQL::Stitching::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/stitching/executor.rb,
lib/graphql/stitching/executor/root_source.rb,
lib/graphql/stitching/executor/resolver_source.rb

Defined Under Namespace

Classes: ResolverSource, RootSource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, nonblocking: false) ⇒ Executor

Returns a new instance of Executor.



22
23
24
25
26
27
28
29
# File 'lib/graphql/stitching/executor.rb', line 22

def initialize(request, nonblocking: false)
  @request = request
  @data = {}
  @errors = []
  @query_count = 0
  @exec_cycles = 0
  @dataloader = GraphQL::Dataloader.new(nonblocking: nonblocking)
end

Instance Attribute Details

#dataHash (readonly)

Returns an aggregate data payload to return.

Returns:

  • (Hash)

    an aggregate data payload to return.



14
15
16
# File 'lib/graphql/stitching/executor.rb', line 14

def data
  @data
end

#errorsArray<Hash> (readonly)

Returns aggregate GraphQL errors to return.

Returns:

  • (Array<Hash>)

    aggregate GraphQL errors to return.



17
18
19
# File 'lib/graphql/stitching/executor.rb', line 17

def errors
  @errors
end

#query_countInteger

Returns tally of queries performed while executing.

Returns:

  • (Integer)

    tally of queries performed while executing.



20
21
22
# File 'lib/graphql/stitching/executor.rb', line 20

def query_count
  @query_count
end

#requestRequest (readonly)

Returns the stitching request to execute.

Returns:

  • (Request)

    the stitching request to execute.



11
12
13
# File 'lib/graphql/stitching/executor.rb', line 11

def request
  @request
end

Instance Method Details

#perform(raw: false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/graphql/stitching/executor.rb', line 31

def perform(raw: false)
  exec!
  result = {}

  if @data && @data.length > 0
    result["data"] = raw ? @data : GraphQL::Stitching::Shaper.new(@request).perform!(@data)
  end

  if @errors.length > 0
    result["errors"] = @errors
  end

  result
end