@@ -1248,16 +1248,26 @@ local function create_root_collection(state)
1248
1248
root_types [what ] = nullable (gql_type (state , root_schema ,
1249
1249
root_collection , nil ))
1250
1250
1251
- end
1252
-
1253
- -- add extra arguments to top-level fields (collections)
1254
- for collection_name , field in pairs (root_types [' Mutation' ].fields ) do
1255
- -- Prevent exposing an argument into the query schema subtree (it is
1256
- -- needed because we use a booking table for arguments).
1257
- field .arguments = table .copy (field .arguments )
1258
-
1259
- for name , arg in pairs (state .extra_arguments [collection_name ]) do
1260
- field .arguments [name ] = arg
1251
+ -- add extra arguments to top-level fields (collections)
1252
+ for collection_name , field in pairs (root_types [what ].fields ) do
1253
+ -- Prevent exposing an argument inserted, say, into the mutation schema
1254
+ -- subtree to the query subtree (it is needed because we use a booking
1255
+ -- table for arguments).
1256
+ field .arguments = table .copy (field .arguments )
1257
+
1258
+ local extra_args = state .extra_arguments [collection_name ]
1259
+ local extra_args_meta = state .extra_arguments_meta [collection_name ]
1260
+
1261
+ for arg_name , arg in pairs (extra_args ) do
1262
+ local meta = extra_args_meta [arg_name ]
1263
+ check (meta , ' meta' , ' table' )
1264
+ -- note: we handle add_to_top_fields_only == false case in
1265
+ -- add_connection_arguments
1266
+ if meta .add_to_top_fields_only and what == ' Mutation' or
1267
+ not meta .add_to_mutations_only then
1268
+ field .arguments [arg_name ] = arg
1269
+ end
1270
+ end
1261
1271
end
1262
1272
end
1263
1273
@@ -1343,6 +1353,8 @@ local function add_connection_arguments(state)
1343
1353
}
1344
1354
end
1345
1355
end )
1356
+
1357
+ -- XXX: handle add_to_top_fields_only == false case of extra_arguments
1346
1358
end
1347
1359
1348
1360
local function parse_cfg (cfg )
@@ -1362,6 +1374,7 @@ local function parse_cfg(cfg)
1362
1374
-- argument. We capture extra_arguments[collection_name] into the resolve
1363
1375
-- function and sure it exists and will not be changed.
1364
1376
state .extra_arguments = utils .gen_booking_table ({})
1377
+ state .extra_arguments_meta = {}
1365
1378
1366
1379
-- map from avro-schema names to graphql types
1367
1380
state .definitions = {}
@@ -1415,12 +1428,16 @@ local function parse_cfg(cfg)
1415
1428
{skip_compound = true })
1416
1429
local list_args = convert_record_fields_to_args (
1417
1430
accessor :list_args (collection_name ))
1418
- local extra_args = convert_record_fields_to_args (
1419
- accessor :extra_args (collection_name ), {dont_skip = true })
1431
+ local extra_args_avro , extra_args_meta = accessor :extra_args (
1432
+ collection_name )
1433
+ check (extra_args_meta , ' extra_args_meta' , ' table' )
1434
+ local extra_args = convert_record_fields_to_args (extra_args_avro ,
1435
+ {dont_skip = true })
1420
1436
1421
1437
state .object_arguments [collection_name ] = object_args
1422
1438
state .list_arguments [collection_name ] = list_args
1423
1439
state .extra_arguments [collection_name ] = extra_args
1440
+ state .extra_arguments_meta [collection_name ] = extra_args_meta
1424
1441
end
1425
1442
1426
1443
add_connection_arguments (state )
@@ -1683,7 +1700,14 @@ end
1683
1700
--- }
1684
1701
--- end,
1685
1702
--- extra_args = function(self, collection_name)
1686
- --- return ...
1703
+ --- ...
1704
+ --- local args_meta = {
1705
+ --- arg_name = {
1706
+ --- add_to_mutations_only = true / false,
1707
+ --- add_to_top_fields_only = true / false,
1708
+ --- }
1709
+ --- }
1710
+ --- return schemas_list, args_meta
1687
1711
--- end
1688
1712
--- }
1689
1713
--- }),
0 commit comments