Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 0999b38

Browse files
committed
Add use_bfs_executor option (.new & :compile)
1 parent 67d7dfe commit 0999b38

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

graphql/impl.lua

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ local function gql_execute(qstate, variables, operation_name)
5656
assert(operation_type == 'query' or operation_type == 'mutation',
5757
'only "query" and "mutation" operation types are supported')
5858
local accessor = state.accessor
59-
60-
if operation_type == 'query' and accessor.name == 'shard' then
59+
local cfg_use_bfs_executor = qstate.query_settings.use_bfs_executor or
60+
state.use_bfs_executor
61+
62+
local use_bfs_executor = operation_type == 'query'
63+
if use_bfs_executor then
64+
if cfg_use_bfs_executor == 'never' then
65+
use_bfs_executor = false
66+
elseif cfg_use_bfs_executor == 'shard' then
67+
use_bfs_executor = accessor.name == 'shard'
68+
elseif cfg_use_bfs_executor == 'always' then
69+
use_bfs_executor = true
70+
else
71+
error('Unknown use_bfs_executor: ' ..
72+
tostring(state.use_bfs_executor))
73+
end
74+
end
75+
if use_bfs_executor then
6176
return bfs_executor.execute(state.schema, qstate.ast, variables,
6277
operation_name, {
6378
qcontext = qcontext,
@@ -117,6 +132,7 @@ end
117132
--- * resulting_object_cnt_max
118133
--- * fetched_object_cnt_max
119134
--- * timeout_ms
135+
--- * use_bfs_executor
120136
---
121137
--- @treturn table compiled query with `execute` and `avro_schema` functions
122138
local function gql_compile(state, query, opts)
@@ -138,6 +154,7 @@ local function gql_compile(state, query, opts)
138154
resulting_object_cnt_max = opts.resulting_object_cnt_max,
139155
fetched_object_cnt_max = opts.fetched_object_cnt_max,
140156
timeout_ms = opts.timeout_ms,
157+
use_bfs_executor = opts.use_bfs_executor,
141158
}
142159
}
143160

@@ -291,6 +308,7 @@ end
291308
--- timeout_ms = <number>,
292309
--- enable_mutations = <boolean>,
293310
--- disable_dangling_check = <boolean>,
311+
--- use_bfs_executor = 'never' | 'shard' (default) | 'always'
294312
--- })
295313
function impl.new(cfg)
296314
local cfg = cfg or {}
@@ -320,8 +338,17 @@ function impl.new(cfg)
320338
cfg.indexes = cfg.accessor.indexes
321339
end
322340

341+
check(cfg.disable_dangling_check, 'disable_dangling_check', 'boolean',
342+
'nil')
343+
check(cfg.use_bfs_executor, 'use_bfs_executor', 'string', 'nil')
344+
assert(cfg.use_bfs_executor == 'never' or cfg.use_bfs_executor == 'shard'
345+
or cfg.use_bfs_executor == 'always' or cfg.use_bfs_executor == nil,
346+
"use_bfs_executor must be 'never', 'shard' (default) or 'always', '" ..
347+
"got " .. tostring(cfg.use_bfs_executor))
348+
323349
local state = {
324350
disable_dangling_check = cfg.disable_dangling_check,
351+
use_bfs_executor = cfg.use_bfs_executor or 'shard',
325352
}
326353
convert_schema.convert(state, cfg)
327354
return setmetatable(state, {

0 commit comments

Comments
 (0)