@@ -41,9 +41,10 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
41
41
exp_result_insert , opts )
42
42
local opts = opts or {}
43
43
local dont_pass_variables = opts .dont_pass_variables or false
44
+ local meta = opts .meta
45
+
44
46
utils .show_trace (function ()
45
47
test :plan (7 )
46
- local NULL_T = 0 -- value in tuple to tag NULL value
47
48
local user_id = ' user_id_new_1'
48
49
local order_id = ' order_id_new_1'
49
50
local variables_insert = {
@@ -70,26 +71,14 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
70
71
-- check inserted user
71
72
local tuple = get_tuple (virtbox , ' user_collection' , {user_id })
72
73
test :ok (tuple ~= nil , ' tuple was inserted' )
73
- local exp_tuple = {
74
- 0 ,
75
- variables_insert .user .user_id ,
76
- variables_insert .user .first_name ,
77
- NULL_T ,
78
- variables_insert .user .middle_name ,
79
- variables_insert .user .last_name ,
80
- }
74
+ local exp_tuple = test_utils .flatten_object (virtbox , meta ,
75
+ ' user_collection' , variables_insert .user , {0 })
81
76
test :is_deeply (tuple :totable (), exp_tuple , ' inserted tuple is correct' )
82
77
-- check inserted order
83
78
local tuple = get_tuple (virtbox , ' order_collection' , {order_id })
84
79
test :ok (tuple ~= nil , ' tuple was inserted' )
85
- local exp_tuple = {
86
- variables_insert .order .order_id ,
87
- variables_insert .order .user_id ,
88
- variables_insert .order .description ,
89
- variables_insert .order .price ,
90
- variables_insert .order .discount ,
91
- variables_insert .order .in_stock or true ,
92
- }
80
+ local exp_tuple = test_utils .flatten_object (virtbox , meta ,
81
+ ' order_collection' , variables_insert .order )
93
82
test :is_deeply (tuple :totable (), exp_tuple , ' inserted tuple is correct' )
94
83
-- clean up inserted tuples & check
95
84
delete_tuple (virtbox , ' user_collection' , {user_id })
@@ -102,10 +91,12 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
102
91
end )
103
92
end
104
93
105
- local function run_queries (gql_wrapper , virtbox )
94
+ local function run_queries (gql_wrapper , virtbox , meta )
106
95
local test = tap .test (' mutation' )
107
96
test :plan (6 )
108
97
98
+ -- {{{ insert
99
+
109
100
local mutation_insert_1 = [[
110
101
mutation insert_user_and_order($user: user_collection_insert,
111
102
$order: order_collection_insert) {
@@ -135,7 +126,7 @@ local function run_queries(gql_wrapper, virtbox)
135
126
]] ):strip ())
136
127
137
128
check_insert (test :test (' insert_1' ), gql_wrapper , virtbox , mutation_insert_1 ,
138
- exp_result_insert_1 )
129
+ exp_result_insert_1 , { meta = meta } )
139
130
140
131
-- the same with immediate argument
141
132
local mutation_insert_1i = [[
@@ -165,7 +156,8 @@ local function run_queries(gql_wrapper, virtbox)
165
156
]]
166
157
167
158
check_insert (test :test (' insert_1i' ), gql_wrapper , virtbox ,
168
- mutation_insert_1i , exp_result_insert_1 , {dont_pass_variables = true })
159
+ mutation_insert_1i , exp_result_insert_1 , {meta = meta ,
160
+ dont_pass_variables = true })
169
161
170
162
-- test "insert" argument is forbidden in a non-top level field
171
163
local mutation_insert_2 = [[
@@ -244,6 +236,8 @@ local function run_queries(gql_wrapper, virtbox)
244
236
245
237
-- XXX: test inserting an object into a collection with subrecords
246
238
239
+ -- }}}
240
+
247
241
-- {{{ inner level inserts: disabled
248
242
--[=[
249
243
0 commit comments