10
10
--- Border cases:
11
11
---
12
12
--- * Unions: as GraphQL specification says "...no fields may be queried on
13
- --- Union type without the use of typed fragments." Tarantool_graphql
14
- --- behaves this way. So 'common fields' are not supported. This does NOT work:
13
+ --- Union type without the use of typed fragments." Tarantool_graphql
14
+ --- behaves this way. So 'common fields' are not supported. This does NOT work:
15
15
---
16
16
--- hero {
17
- -- hero_id -- common field
18
- -- ... on human {
19
- -- name
20
- -- }
21
- -- ... on droid {
22
- -- model
23
- -- }
24
- -- }
17
+ --- hero_id -- common field
18
+ --- ... on human {
19
+ --- name
20
+ --- }
21
+ --- ... on droid {
22
+ --- model
23
+ --- }
24
+ --- }
25
25
--- (GraphQL spec: http://facebook.github.io/graphql/October2016/#sec-Unions)
26
26
--- Also, no arguments are currently allowed for fragments.
27
27
--- See issue about this (https://github.com/facebook/graphql/issues/204)
@@ -271,7 +271,8 @@ local function convert_record_fields(state, fields)
271
271
return res
272
272
end
273
273
274
- local args_from_destination_collection = function (state , collection , connection_type )
274
+ local function args_from_destination_collection (state , collection ,
275
+ connection_type )
275
276
if connection_type == ' 1:1' then
276
277
return state .object_arguments [collection ]
277
278
elseif connection_type == ' 1:1*' then
@@ -283,7 +284,7 @@ local args_from_destination_collection = function(state, collection, connection_
283
284
end
284
285
end
285
286
286
- local specify_destination_type = function (destination_type , connection_type )
287
+ local function specify_destination_type (destination_type , connection_type )
287
288
if connection_type == ' 1:1' then
288
289
return types .nonNull (destination_type )
289
290
elseif connection_type == ' 1:1*' then
@@ -295,7 +296,7 @@ local specify_destination_type = function (destination_type, connection_type)
295
296
end
296
297
end
297
298
298
- local parent_args_values = function (parent , connection_parts )
299
+ local function parent_args_values (parent , connection_parts )
299
300
local destination_args_names = {}
300
301
local destination_args_values = {}
301
302
for _ , part in ipairs (connection_parts ) do
@@ -309,8 +310,7 @@ local parent_args_values = function(parent, connection_parts)
309
310
destination_args_names [# destination_args_names + 1 ] =
310
311
part .destination_field
311
312
local value = parent [part .source_field ]
312
- destination_args_values [# destination_args_values + 1 ] =
313
- value
313
+ destination_args_values [# destination_args_values + 1 ] = value
314
314
end
315
315
316
316
return destination_args_names , destination_args_values
@@ -320,13 +320,13 @@ end
320
320
-- destination object(s). Note that connection key parts
321
321
-- can be prefix of index key parts. Zero parts count
322
322
-- considered as ok by this check.
323
- local are_all_parts_null = function (parent , connection_parts )
323
+ local function are_all_parts_null (parent , connection_parts )
324
324
local are_all_parts_null = true
325
325
local are_all_parts_non_null = true
326
326
for _ , part in ipairs (connection_parts ) do
327
327
local value = parent [part .source_field ]
328
328
329
- if value ~= nil then -- nil of s/ box.NonNull/box. NULL/
329
+ if value ~= nil then -- nil or box.NULL
330
330
are_all_parts_null = false
331
331
else
332
332
are_all_parts_non_null = false
@@ -336,16 +336,16 @@ local are_all_parts_null = function(parent, connection_parts)
336
336
local ok = are_all_parts_null or are_all_parts_non_null
337
337
if not ok then -- avoid extra json.encode()
338
338
assert (ok ,
339
- ' FULL MATCH constraint was failed: connection ' ..
340
- ' key parts must be all non-nulls or all nulls; ' ..
341
- ' object: ' .. json .encode (parent ))
339
+ ' FULL MATCH constraint was failed: connection ' ..
340
+ ' key parts must be all non-nulls or all nulls; ' ..
341
+ ' object: ' .. json .encode (parent ))
342
342
end
343
343
344
344
return are_all_parts_null
345
345
end
346
346
347
- local check_args_instance = function (args_instance , connection_args ,
348
- connection_list_args )
347
+ local function separate_args_instance (args_instance , connection_args ,
348
+ connection_list_args )
349
349
local object_args_instance = {}
350
350
local list_args_instance = {}
351
351
for k , v in pairs (args_instance ) do
@@ -355,12 +355,13 @@ local check_args_instance = function(args_instance, connection_args,
355
355
object_args_instance [k ] = v
356
356
else
357
357
error ((' cannot found "%s" field ("%s" value) ' ..
358
- ' within allowed fields' ):format (tostring (k ),
359
- tostring (v )))
358
+ ' within allowed fields' ):format (tostring (k ),
359
+ tostring (v )))
360
360
end
361
361
end
362
362
return object_args_instance , list_args_instance
363
363
end
364
+
364
365
--- The function converts passed simple connection to a field of GraphQL type.
365
366
---
366
367
--- @tparam table state for read state.accessor and previously filled
373
374
--- @tparam table connection simple connection to create field on
374
375
--- @tparam table collection_name name of the collection which has given
375
376
--- connection
376
- local convert_simple_connection = function (state , connection , collection_name )
377
+ local function convert_simple_connection (state , connection , collection_name )
377
378
local c = connection
378
379
assert (type (c .destination_collection ) == ' string' ,
379
380
' connection.destination_collection must be a string, got ' ..
@@ -417,7 +418,7 @@ local convert_simple_connection = function(state, connection, collection_name)
417
418
(' only 1:1* or 1:N connections can have ' ..
418
419
' all key parts null; parent is %s from ' ..
419
420
' collection "%s"' ):format (json .encode (parent ),
420
- tostring (collection_name )))
421
+ tostring (collection_name )))
421
422
end
422
423
return c .type == ' 1:N' and {} or nil
423
424
end
@@ -432,11 +433,10 @@ local convert_simple_connection = function(state, connection, collection_name)
432
433
qcontext = info .qcontext
433
434
}
434
435
435
- -- object_args_instance -- passed to 'filter'
436
- -- list_args_instance -- passed to 'args'
437
-
436
+ -- object_args_instance will be passed to 'filter'
437
+ -- list_args_instance will be passed to 'args'
438
438
local object_args_instance , list_args_instance =
439
- check_args_instance (args_instance , c_args , c_list_args )
439
+ separate_args_instance (args_instance , c_args , c_list_args )
440
440
441
441
local objs = state .accessor :select (parent ,
442
442
c .destination_collection , from ,
469
469
--- @tparam table connection union connection to create field on
470
470
--- @tparam table collection_name name of the collection which has given
471
471
--- connection
472
- local convert_union_connection = function (state , connection , collection_name )
472
+ local function convert_union_connection (state , connection , collection_name )
473
473
local c = connection
474
474
local union_types = {}
475
475
local collection_to_arguments = {}
@@ -495,8 +495,6 @@ local convert_union_connection = function(state, connection, collection_name)
495
495
v .destination_collection , c .type )
496
496
destination_type = specify_destination_type (destination_type , c .type )
497
497
498
-
499
-
500
498
local v_list_args = state .list_arguments [v .destination_collection ]
501
499
502
500
union_types [# union_types + 1 ] = destination_type
@@ -538,7 +536,7 @@ local convert_union_connection = function(state, connection, collection_name)
538
536
name = c .name ,
539
537
types = union_types ,
540
538
}),
541
- arguments = nil ,
539
+ arguments = nil ,
542
540
resolve = function (parent , args_instance , info )
543
541
local v , variant_num = resolve_variant (parent )
544
542
local destination_type = union_types [variant_num ]
@@ -582,7 +580,7 @@ local convert_union_connection = function(state, connection, collection_name)
582
580
-- list_args_instance -- passed to 'args'
583
581
584
582
local object_args_instance , list_args_instance =
585
- check_args_instance (args_instance , c_args , c_list_args )
583
+ separate_args_instance (args_instance , c_args , c_list_args )
586
584
587
585
local objs = state .accessor :select (parent ,
588
586
v .destination_collection , from ,
0 commit comments