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

Commit 1362b00

Browse files
committed
Fix problem with multihead connections with nulls
Close #200
1 parent 3ebe39d commit 1362b00

File tree

3 files changed

+491
-0
lines changed

3 files changed

+491
-0
lines changed

graphql/convert_schema/resolve.lua

+19
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ function resolve.gen_resolve_function_multihead(collection_name, connection,
190190
end
191191

192192
return function(parent, _, info)
193+
-- If parent object does not have all source_fields (for any of
194+
-- variants) non-nill then we do not resolve variant and just return
195+
-- box.NULL
196+
for _, variant in ipairs(c.variants) do
197+
for _, p in ipairs(variant.parts) do
198+
local found = false
199+
for field_name, value in pairs(parent) do
200+
if field_name == p.source_field and value ~= nil then
201+
found = true
202+
break
203+
end
204+
end
205+
206+
if not found then
207+
return box.NULL, nil
208+
end
209+
end
210+
end
211+
193212
local v, variant_num, box_field_name = resolve_variant(parent)
194213
local destination_type = union_types[variant_num]
195214

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env tarantool
2+
3+
local fio = require('fio')
4+
5+
-- require in-repo version of graphql/ sources despite current working directory
6+
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
7+
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
8+
9+
local test_utils = require('test.test_utils')
10+
local testdata = require('test.testdata.multihead_conn_testdata_with_nulls')
11+
12+
box.cfg({})
13+
14+
test_utils.run_testdata(testdata)
15+
16+
os.exit()

0 commit comments

Comments
 (0)