-
Notifications
You must be signed in to change notification settings - Fork 3
Support of nesting a record into a record #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
local net_box = require('net.box') | ||
local shard = require('shard') | ||
|
||
local initialized = false | ||
|
||
local function instance_uri(instance_id) | ||
local socket_dir = require('fio').cwd() | ||
|
@@ -9,13 +11,21 @@ local function instance_uri(instance_id) | |
end | ||
|
||
local function init_shard(test_run, servers, config) | ||
local shard = require('shard') | ||
local suite = "common" | ||
local suite = 'common' | ||
test_run:create_cluster(servers, suite) | ||
box.once('init_shard_module', function() | ||
|
||
-- XXX: for now we always use one shard configuration (a first one), | ||
-- because it is unclear how to reload shard module with an another | ||
-- configuration; the another way is use several test configurations, but | ||
-- it seems to be non-working in 'core = app' tests with current test-run. | ||
-- Ways to better handle this is subject to future digging. | ||
local shard = require('shard') | ||
if not initialized then | ||
shard.init(config) | ||
end) | ||
initialized = true | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the code with the comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed the following issue for this problem: tarantool/graphql#57 |
||
shard.wait_connection() | ||
return shard | ||
end | ||
|
||
local function shard_cleanup(test_run, servers) | ||
|
@@ -29,6 +39,14 @@ local function shard_cleanup(test_run, servers) | |
end | ||
end | ||
|
||
local function for_each_server(shard, func) | ||
for _, zone in ipairs(shard.shards) do | ||
for _, node in ipairs(zone) do | ||
func(node.uri) | ||
end | ||
end | ||
end | ||
|
||
-- Run tests on multiple accessors and configurations. | ||
-- Feel free to add more configurations. | ||
local function run(test_run, init_function, cleanup_function, callback) | ||
|
@@ -38,8 +56,8 @@ local function run(test_run, init_function, cleanup_function, callback) | |
|
||
local servers = {'shard1', 'shard2', 'shard3', 'shard4'}; | ||
|
||
-- Test sharding without redundancy = 2. | ||
init_shard(test_run, servers, { | ||
-- Test sharding with redundancy = 2. | ||
local shard = init_shard(test_run, servers, { | ||
servers = { | ||
{ uri = instance_uri('1'), zone = '0' }, | ||
{ uri = instance_uri('2'), zone = '1' }, | ||
|
@@ -50,23 +68,23 @@ local function run(test_run, init_function, cleanup_function, callback) | |
password = '', | ||
redundancy = 2, | ||
monitor = false | ||
}); | ||
}) | ||
|
||
for _, shard_server in ipairs(shard_status().online) do | ||
local c = net_box.connect(shard_server.uri) | ||
for_each_server(shard, function(uri) | ||
local c = net_box.connect(uri) | ||
c:eval(init_script) | ||
end | ||
end) | ||
|
||
callback("Shard 2x2", shard) | ||
|
||
for _, shard_server in ipairs(shard_status().online) do | ||
local c = net_box.connect(shard_server.uri) | ||
for_each_server(shard, function(uri) | ||
local c = net_box.connect(uri) | ||
c:eval(cleanup_script) | ||
end | ||
end) | ||
shard_cleanup(test_run, servers) | ||
|
||
-- Test sharding without redundancy. | ||
init_shard(test_run, servers, { | ||
local shard = init_shard(test_run, servers, { | ||
servers = { | ||
{ uri = instance_uri('1'), zone = '0' }, | ||
{ uri = instance_uri('2'), zone = '1' }, | ||
|
@@ -77,19 +95,19 @@ local function run(test_run, init_function, cleanup_function, callback) | |
password = '', | ||
redundancy = 1, | ||
monitor = false | ||
}); | ||
}) | ||
|
||
for _, shard_server in ipairs(shard_status().online) do | ||
local c = net_box.connect(shard_server.uri) | ||
for_each_server(shard, function(uri) | ||
local c = net_box.connect(uri) | ||
c:eval(init_script) | ||
end | ||
end) | ||
|
||
callback("Shard 4x1", shard) | ||
|
||
for _, shard_server in ipairs(shard_status().online) do | ||
local c = net_box.connect(shard_server.uri) | ||
for_each_server(shard, function(uri) | ||
local c = net_box.connect(uri) | ||
c:eval(cleanup_script) | ||
end | ||
end) | ||
shard_cleanup(test_run, servers) | ||
|
||
-- Test local setup (box). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
-- Nested record inside a record | ||
-- https://github.com/tarantool/graphql/issues/46 | ||
-- https://github.com/tarantool/graphql/issues/49 | ||
|
||
local json = require('json') | ||
local yaml = require('yaml') | ||
local utils = require('graphql.utils') | ||
|
||
local testdata = {} | ||
|
||
testdata.meta = { | ||
schemas = json.decode([[{ | ||
"user": { | ||
"type": "record", | ||
"name": "user", | ||
"fields": [ | ||
{"name": "uid", "type": "long"}, | ||
{"name": "p1", "type": "string"}, | ||
{"name": "p2", "type": "string"}, | ||
{ | ||
"name": "nested", | ||
"type": { | ||
"type": "record", | ||
"name": "nested", | ||
"fields": [ | ||
{"name": "x", "type": "long"}, | ||
{"name": "y", "type": "long"} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}]]), | ||
collections = json.decode([[{ | ||
"user": { | ||
"schema_name": "user", | ||
"connections": [] | ||
} | ||
}]]), | ||
service_fields = { | ||
user = {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty list of service fields. Don’t sure we allow to skip it, but that has sense, yep. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skipped for now. |
||
}, | ||
indexes = { | ||
user = { | ||
uid = { | ||
service_fields = {}, | ||
fields = {'uid'}, | ||
index_type = 'tree', | ||
unique = true, | ||
primary = true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
|
||
function testdata.init_spaces() | ||
-- user fields | ||
local UID_FN = 1 | ||
|
||
box.schema.create_space('user') | ||
box.space.user:create_index('uid', { | ||
type = 'tree', unique = true, parts = {UID_FN, 'unsigned'}}) | ||
end | ||
|
||
function testdata.drop_spaces() | ||
box.space.user:drop() | ||
end | ||
|
||
function testdata.fill_test_data(virtbox) | ||
for i = 1, 15 do | ||
local uid = i | ||
local p1 = 'p1 ' .. tostring(i) | ||
local p2 = 'p2 ' .. tostring(i) | ||
local x = 1000 + i | ||
local y = 2000 + i | ||
virtbox.user:replace({uid, p1, p2, x, y}) | ||
end | ||
end | ||
|
||
function testdata.run_queries(gql_wrapper) | ||
local output = '' | ||
|
||
local query_1 = [[ | ||
query getUserByUid($uid: Long) { | ||
user(uid: $uid) { | ||
uid | ||
p1 | ||
p2 | ||
nested { | ||
x | ||
y | ||
} | ||
} | ||
} | ||
]] | ||
|
||
local variables_1 = {uid = 5} | ||
local result_1 = utils.show_trace(function() | ||
local gql_query_1 = gql_wrapper:compile(query_1) | ||
return gql_query_1:execute(variables_1) | ||
end) | ||
|
||
output = output .. 'RUN 1 {{{\n' .. | ||
(('QUERY\n%s'):format(query_1:rstrip())) .. '\n' .. | ||
(('VARIABLES\n%s'):format(yaml.encode(variables_1))) .. '\n' .. | ||
(('RESULT\n%s'):format(yaml.encode(result_1))) .. '\n' .. | ||
'}}}\n' | ||
|
||
--[=[ | ||
local query_2 = [[ | ||
query getUserByX($x: Long) { | ||
user(nested: {x: $x}) { | ||
uid | ||
p1 | ||
p2 | ||
nested { | ||
x | ||
y | ||
} | ||
} | ||
} | ||
]] | ||
|
||
local variables_2 = {x = 1005} | ||
local result_2 = utils.show_trace(function() | ||
local gql_query_2 = gql_wrapper:compile(query_2) | ||
return gql_query_2:execute(variables_2) | ||
end) | ||
|
||
output = output .. 'RUN 2 {{{\n' .. | ||
(('QUERY\n%s'):format(query_2:rstrip())) .. '\n' .. | ||
(('VARIABLES\n%s'):format(yaml.encode(variables_2))) .. '\n' .. | ||
(('RESULT\n%s'):format(yaml.encode(result_2))) .. '\n' .. | ||
'}}}\n' | ||
]=]-- | ||
|
||
return output:rstrip() | ||
end | ||
|
||
return testdata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you call nullable without any conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was that you can omit any argument. But AFAIR it is so even if you don’t use 'nullable'.