Skip to content

Commit 2394ca1

Browse files
committed
Make shard optional
Fixes tarantool#218.
1 parent 9633093 commit 2394ca1

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

graphql/accessor_shard_cache.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local json = require('json')
2-
local shard = require('shard')
32
local utils = require('graphql.utils')
3+
local shard = utils.optional_require('shard')
44
local request_batch = require('graphql.request_batch')
55
local accessor_shard_index_info = require('graphql.accessor_shard_index_info')
66

test/extra/no_shard/shard.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error('shard should not be mandatory dependency')

test/extra/shard_optional.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env tarantool
2+
3+
-- https://github.com/tarantool/graphql/issues/218
4+
5+
local fio = require('fio')
6+
local tap = require('tap')
7+
8+
-- require in-repo version of graphql/ sources despite current working directory
9+
local cur_dir = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
10+
:gsub('/./', '/'):gsub('/+$', ''))
11+
package.path =
12+
cur_dir .. '/../../?/init.lua' .. ';' ..
13+
cur_dir .. '/../../?.lua' .. ';' ..
14+
package.path
15+
16+
-- require no_shard/shard.lua instead of the real shard module
17+
package.path =
18+
cur_dir .. '/no_shard/?/init.lua' .. ';' ..
19+
cur_dir .. '/no_shard/?.lua' .. ';' ..
20+
package.path
21+
22+
local graphql = require('graphql')
23+
local testdata = require('test.testdata.common_testdata')
24+
25+
local test = tap.test('optional shard')
26+
test:plan(1)
27+
28+
box.cfg{wal_mode='none'}
29+
30+
local cfg = testdata.get_test_metadata()
31+
cfg.accessor = 'space'
32+
local ok = pcall(graphql.new, cfg)
33+
test:ok(ok, 'shard is optional')
34+
35+
os.exit(test:check() == true and 0 or 1)

test/test_utils.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ local log = require('log')
1010
local yaml = require('yaml')
1111
local avro_schema = require('avro_schema')
1212
local digest = require('digest')
13-
local shard = require('shard')
13+
local utils = require('graphql.utils')
14+
local shard = utils.optional_require('shard')
1415
local graphql = require('graphql')
1516
local multirunner = require('test.common.multirunner')
16-
local utils = require('graphql.utils')
1717
local test_run = utils.optional_require('test_run')
1818
test_run = test_run and test_run.new()
1919

0 commit comments

Comments
 (0)