33
33
---
34
34
--- Note that connection key parts can be prefix of index key parts. Zero parts
35
35
--- count considered as ok by this check.
36
- local function are_all_parts_null (parent , connection_parts )
36
+ local function are_all_parts_null (parent , connection_parts , opts )
37
37
local are_all_parts_null = true
38
38
local are_all_parts_non_null = true
39
39
for _ , part in ipairs (connection_parts ) do
@@ -47,7 +47,9 @@ local function are_all_parts_null(parent, connection_parts)
47
47
end
48
48
49
49
local ok = are_all_parts_null or are_all_parts_non_null
50
- if not ok then -- avoid extra json.encode()
50
+ local opts = opts or {}
51
+ local no_assert = opts .no_assert or false
52
+ if not ok and not no_assert then -- avoid extra json.encode()
51
53
assert (ok ,
52
54
' FULL MATCH constraint was failed: connection ' ..
53
55
' key parts must be all non-nulls or all nulls; ' ..
@@ -190,6 +192,22 @@ function resolve.gen_resolve_function_multihead(collection_name, connection,
190
192
end
191
193
192
194
return function (parent , _ , info )
195
+ -- If a parent object does not have all source fields (for any of
196
+ -- variants) non-null then we do not resolve variant and just return
197
+ -- box.NULL.
198
+ local is_source_fields_found = false
199
+ for _ , variant in ipairs (c .variants ) do
200
+ is_source_fields_found =
201
+ not are_all_parts_null (parent , variant .parts , {no_assert = true })
202
+ if is_source_fields_found then
203
+ break
204
+ end
205
+ end
206
+
207
+ if not is_source_fields_found then
208
+ return box .NULL , nil
209
+ end
210
+
193
211
local v , variant_num , box_field_name = resolve_variant (parent )
194
212
local destination_type = union_types [variant_num ]
195
213
0 commit comments