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

Commit c29493d

Browse files
committed
style fixes during review 3
1 parent a95dacd commit c29493d

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

graphql/accessor_general.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -699,14 +699,14 @@ local function validate_collections(collections, schemas)
699699
local schema_name = collection.schema_name
700700
assert(type(schema_name) == 'string',
701701
'collection.schema_name must be a string, got ' ..
702-
type(schema_name))
702+
type(schema_name))
703703
assert(schemas[schema_name] ~= nil,
704704
('cannot find schema "%s" for collection "%s"'):format(
705-
schema_name, collection_name))
705+
schema_name, collection_name))
706706
local connections = collection.connections
707707
assert(connections == nil or type(connections) == 'table',
708-
'collection.connections must be nil or table, got ' ..
709-
type(connections))
708+
'collection.connections must be nil or table, got ' ..
709+
type(connections))
710710
for _, connection in ipairs(connections) do
711711
assert(type(connection) == 'table',
712712
'connection must be a table, got ' .. type(connection))
@@ -715,27 +715,27 @@ local function validate_collections(collections, schemas)
715715
type(connection.name))
716716
if connection.destination_collection then
717717
assert(type(connection.destination_collection) == 'string',
718-
'connection.destination_collection must be a string, got ' ..
718+
'connection.destination_collection must be a string, got ' ..
719719
type(connection.destination_collection))
720720
assert(type(connection.parts) == 'table',
721-
'connection.parts must be a string, got ' ..
721+
'connection.parts must be a string, got ' ..
722722
type(connection.parts))
723723
assert(type(connection.index_name) == 'string',
724-
'connection.index_name must be a string, got ' ..
724+
'connection.index_name must be a string, got ' ..
725725
type(connection.index_name))
726726
elseif connection.variants then
727727
for _, v in pairs(connection.variants) do
728-
assert(type(v.determinant) == 'table', "variant's " ..
729-
"determinant must be a table, got " ..
730-
type(v.determinant))
731-
assert(type(v.destination_collection) == 'string',
732-
'variant.destination_collection must be a string, ' ..
733-
'got ' .. type(v.destination_collection))
734-
assert(type(v.parts) == 'table',
735-
'variant.parts must be a table, got ' .. type(v.parts))
736-
assert(type(v.index_name) == 'string',
737-
'variant.index_name must be a string, got ' ..
738-
type(v.index_name))
728+
assert(type(v.determinant) == 'table', "variant's " ..
729+
"determinant must be a table, got " ..
730+
type(v.determinant))
731+
assert(type(v.destination_collection) == 'string',
732+
'variant.destination_collection must be a string, ' ..
733+
'got ' .. type(v.destination_collection))
734+
assert(type(v.parts) == 'table',
735+
'variant.parts must be a table, got ' .. type(v.parts))
736+
assert(type(v.index_name) == 'string',
737+
'variant.index_name must be a string, got ' ..
738+
type(v.index_name))
739739
end
740740
else
741741
assert(false, ('connection "%s" of collection "%s" doesn\'t ' ..

graphql/core/execute.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ end
7070

7171
local evaluateSelections
7272

73+
--@todo resolveType optional comments
7374
local function completeValue(fieldType, result, subSelections, context, resolvedType)
7475
local fieldTypeName = fieldType.__type
7576

@@ -113,7 +114,7 @@ local function completeValue(fieldType, result, subSelections, context, resolved
113114
elseif fieldTypeName == 'Interface' or fieldTypeName == 'Union' then
114115

115116
local objectType = resolvedType or fieldType.resolveType(result)
116-
if objectType.__type == 'NonNull' then
117+
while objectType.__type == 'NonNull' do
117118
objectType = objectType.ofType
118119
end
119120

@@ -155,10 +156,11 @@ local function getFieldEntry(objectType, object, fields, context)
155156
variableValues = context.variables,
156157
qcontext = context.qcontext
157158
}
158-
159+
--@todo add comment
159160
local resolvedObject, resolvedType = (fieldType.resolve or defaultResolver)(object, arguments, info)
160161
local subSelections = query_util.mergeSelectionSets(fields)
161162

163+
--@todo add comment
162164
return completeValue(fieldType.kind, resolvedObject, subSelections, context, resolvedType)
163165
end
164166

graphql/core/rules.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,11 @@ function rules.fragmentSpreadIsPossible(node, context)
324324

325325
local valid = util.find(parentTypes, function(kind)
326326
local kind = kind
327-
-- Graphql-lua does not this check correctly in the case of NonNull
328-
-- wrapped fragment types. Next line fixes that
329-
if kind.__type == 'NonNull' then
327+
-- Here is the check that type, mentioned in '... on some_type'
328+
-- conditional fragment expression is type of some field of parent object.
329+
-- In case of Union parent object and NonNull wrapped inner types
330+
-- graphql-lua missed unwrapping so we add it here
331+
while kind.__type == 'NonNull' do
330332
kind = kind.ofType
331333
end
332334
return fragmentTypes[kind]

graphql/tarantool_graphql.lua

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
--- Border cases:
1111
---
1212
--- * 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:
1515
---
1616
--- 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+
--- }
2525
--- (GraphQL spec: http://facebook.github.io/graphql/October2016/#sec-Unions)
2626
--- Also, no arguments are currently allowed for fragments.
2727
--- See issue about this (https://github.com/facebook/graphql/issues/204)
@@ -271,7 +271,8 @@ local function convert_record_fields(state, fields)
271271
return res
272272
end
273273

274-
local args_from_destination_collection = function(state, collection, connection_type)
274+
local function args_from_destination_collection(state, collection,
275+
connection_type)
275276
if connection_type == '1:1' then
276277
return state.object_arguments[collection]
277278
elseif connection_type == '1:1*' then
@@ -283,7 +284,7 @@ local args_from_destination_collection = function(state, collection, connection_
283284
end
284285
end
285286

286-
local specify_destination_type = function (destination_type, connection_type)
287+
local function specify_destination_type(destination_type, connection_type)
287288
if connection_type == '1:1' then
288289
return types.nonNull(destination_type)
289290
elseif connection_type == '1:1*' then
@@ -295,7 +296,7 @@ local specify_destination_type = function (destination_type, connection_type)
295296
end
296297
end
297298

298-
local parent_args_values = function(parent, connection_parts)
299+
local function parent_args_values(parent, connection_parts)
299300
local destination_args_names = {}
300301
local destination_args_values = {}
301302
for _, part in ipairs(connection_parts) do
@@ -309,8 +310,7 @@ local parent_args_values = function(parent, connection_parts)
309310
destination_args_names[#destination_args_names + 1] =
310311
part.destination_field
311312
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
314314
end
315315

316316
return destination_args_names, destination_args_values
@@ -320,13 +320,13 @@ end
320320
-- destination object(s). Note that connection key parts
321321
-- can be prefix of index key parts. Zero parts count
322322
-- 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)
324324
local are_all_parts_null = true
325325
local are_all_parts_non_null = true
326326
for _, part in ipairs(connection_parts) do
327327
local value = parent[part.source_field]
328328

329-
if value ~= nil then -- nil of s/box.NonNull/box.NULL/
329+
if value ~= nil then -- nil or box.NULL
330330
are_all_parts_null = false
331331
else
332332
are_all_parts_non_null = false
@@ -336,16 +336,16 @@ local are_all_parts_null = function(parent, connection_parts)
336336
local ok = are_all_parts_null or are_all_parts_non_null
337337
if not ok then -- avoid extra json.encode()
338338
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))
342342
end
343343

344344
return are_all_parts_null
345345
end
346346

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)
349349
local object_args_instance = {}
350350
local list_args_instance = {}
351351
for k, v in pairs(args_instance) do
@@ -355,12 +355,13 @@ local check_args_instance = function(args_instance, connection_args,
355355
object_args_instance[k] = v
356356
else
357357
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)))
360360
end
361361
end
362362
return object_args_instance, list_args_instance
363363
end
364+
364365
--- The function converts passed simple connection to a field of GraphQL type.
365366
---
366367
--- @tparam table state for read state.accessor and previously filled
@@ -373,7 +374,7 @@ end
373374
--- @tparam table connection simple connection to create field on
374375
--- @tparam table collection_name name of the collection which has given
375376
--- connection
376-
local convert_simple_connection = function(state, connection, collection_name)
377+
local function convert_simple_connection(state, connection, collection_name)
377378
local c = connection
378379
assert(type(c.destination_collection) == 'string',
379380
'connection.destination_collection must be a string, got ' ..
@@ -417,7 +418,7 @@ local convert_simple_connection = function(state, connection, collection_name)
417418
('only 1:1* or 1:N connections can have ' ..
418419
'all key parts null; parent is %s from ' ..
419420
'collection "%s"'):format(json.encode(parent),
420-
tostring(collection_name)))
421+
tostring(collection_name)))
421422
end
422423
return c.type == '1:N' and {} or nil
423424
end
@@ -432,11 +433,10 @@ local convert_simple_connection = function(state, connection, collection_name)
432433
qcontext = info.qcontext
433434
}
434435

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'
438438
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)
440440

441441
local objs = state.accessor:select(parent,
442442
c.destination_collection, from,
@@ -469,7 +469,7 @@ end
469469
--- @tparam table connection union connection to create field on
470470
--- @tparam table collection_name name of the collection which has given
471471
--- connection
472-
local convert_union_connection = function(state, connection, collection_name)
472+
local function convert_union_connection(state, connection, collection_name)
473473
local c = connection
474474
local union_types = {}
475475
local collection_to_arguments = {}
@@ -495,8 +495,6 @@ local convert_union_connection = function(state, connection, collection_name)
495495
v.destination_collection, c.type)
496496
destination_type = specify_destination_type(destination_type, c.type)
497497

498-
499-
500498
local v_list_args = state.list_arguments[v.destination_collection]
501499

502500
union_types[#union_types + 1] = destination_type
@@ -538,7 +536,7 @@ local convert_union_connection = function(state, connection, collection_name)
538536
name = c.name,
539537
types = union_types,
540538
}),
541-
arguments = nil,
539+
arguments = nil,
542540
resolve = function(parent, args_instance, info)
543541
local v, variant_num = resolve_variant(parent)
544542
local destination_type = union_types[variant_num]
@@ -582,7 +580,7 @@ local convert_union_connection = function(state, connection, collection_name)
582580
--list_args_instance -- passed to 'args'
583581

584582
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)
586584

587585
local objs = state.accessor:select(parent,
588586
v.destination_collection, from,

0 commit comments

Comments
 (0)