@@ -1403,29 +1403,23 @@ end
1403
1403
--- Provided `funcs` argument determines certain functions for retrieving
1404
1404
--- tuples.
1405
1405
---
1406
- --- @tparam table opts `schemas`, `collections`, `service_fields`, `indexes` and
1407
- --- `collection_use_tomap` ({[collection_name] = whether objects in collection
1408
- --- collection_name intended to be unflattened using tuple:tomap({names_only = true})
1409
- --- method instead of compiled_avro_schema.unflatten(tuple), ...})
1410
- --- to give the data accessor all needed meta-information re data; the format is
1411
- --- shown below; additional attributes `resulting_object_cnt_max` and
1412
- --- `fetched_object_cnt_max` are optional positive numbers which help to control
1413
- --- query behaviour in case it requires more resources than expected _(default
1414
- --- value is 10,000)_; `timeout_ms` _(default is 1000)_
1415
- ---
1416
- --- @tparam table funcs set of functions:
1417
- ---
1418
- --- * `is_collection_exists`,
1419
- --- * `get_index`,
1420
- --- * `get_primary_index`,
1421
- --- * `unflatten_tuple`,
1422
- --- * `flatten_object`,
1423
- --- * `insert_tuple`.
1424
- ---
1425
- --- They allows this abstract data accessor behaves in the certain way (say,
1426
- --- like space data accessor or shard data accessor); consider the
1427
- --- `accessor_space` and the `accessor_shard` modules documentation for these
1428
- --- functions description.
1406
+ --- @tparam table opts set of options:
1407
+ ---
1408
+ --- * `schemas`,
1409
+ --- * `collections`,
1410
+ --- * `service_fields`,
1411
+ --- * `indexes`,
1412
+ --- * `collection_use_tomap`: ({[collection_name] = whether objects in
1413
+ --- collection `collection_name` intended to be unflattened using
1414
+ --- `tuple:tomap({names_only = true}` method instead of
1415
+ --- `compiled_avro_schema.unflatten(tuple), ...}`),
1416
+ --- * `resulting_object_cnt_max` and `fetched_object_cnt_max` are optional
1417
+ --- positive numbers which help to control query behaviour in case it
1418
+ --- requires more resources than expected _(default value is 10,000 for
1419
+ --- both)_,
1420
+ --- * `timeout_ms` _(default is 1000)_,
1421
+ --- * `enable_mutations`: boolean flag _(default is `false` for avro-schema-2*
1422
+ --- and `true` for avro-schema-3*)_.
1429
1423
---
1430
1424
--- For examples of `opts.schemas` and `opts.collections` consider the
1431
1425
--- @{tarantool_graphql.new} function description.
@@ -1452,6 +1446,20 @@ end
1452
1446
--- ...
1453
1447
--- }
1454
1448
---
1449
+ --- @tparam table funcs set of functions:
1450
+ ---
1451
+ --- * `is_collection_exists`,
1452
+ --- * `get_index`,
1453
+ --- * `get_primary_index`,
1454
+ --- * `unflatten_tuple`,
1455
+ --- * `flatten_object`,
1456
+ --- * `insert_tuple`.
1457
+ ---
1458
+ --- They allows this abstract data accessor behaves in the certain way (say,
1459
+ --- like space data accessor or shard data accessor); consider the
1460
+ --- `accessor_space` and the `accessor_shard` modules documentation for these
1461
+ --- functions description.
1462
+ ---
1455
1463
--- @treturn table data accessor instance, a table with the two methods
1456
1464
--- (`select` and `arguments`) as described in the @{tarantool_graphql.new}
1457
1465
--- function description.
@@ -1471,6 +1479,14 @@ function accessor_general.new(opts, funcs)
1471
1479
DEF_FETCHED_OBJECT_CNT_MAX
1472
1480
-- TODO: move this setting to `tgql.compile` after #59
1473
1481
local timeout_ms = opts .timeout_ms or DEF_TIMEOUT_MS
1482
+ -- Mutations are disabled for avro-schema-2*, because it can work
1483
+ -- incorrectly for schemas with nullable types.
1484
+ local enable_mutations
1485
+ if opts .enable_mutations == nil then
1486
+ enable_mutations = avro_helpers .major_avro_schema_version () == 3
1487
+ else
1488
+ enable_mutations = opts .enable_mutations
1489
+ end
1474
1490
1475
1491
assert (type (schemas ) == ' table' ,
1476
1492
' schemas must be a table, got ' .. type (schemas ))
@@ -1492,6 +1508,7 @@ function accessor_general.new(opts, funcs)
1492
1508
assert (timeout_ms <= TIMEOUT_INFINITY ,
1493
1509
(' timeouts more then graphql.TIMEOUT_INFINITY (%s) ' ..
1494
1510
' do not supported' ):format (tostring (TIMEOUT_INFINITY )))
1511
+ check (enable_mutations , ' enable_mutations' , ' boolean' )
1495
1512
1496
1513
local models , service_fields_defaults = compile_schemas (schemas ,
1497
1514
service_fields )
@@ -1521,7 +1538,8 @@ function accessor_general.new(opts, funcs)
1521
1538
settings = {
1522
1539
resulting_object_cnt_max = resulting_object_cnt_max ,
1523
1540
fetched_object_cnt_max = fetched_object_cnt_max ,
1524
- timeout_ms = timeout_ms
1541
+ timeout_ms = timeout_ms ,
1542
+ enable_mutations = enable_mutations ,
1525
1543
}
1526
1544
}, {
1527
1545
__index = {
@@ -1567,6 +1585,10 @@ function accessor_general.new(opts, funcs)
1567
1585
}
1568
1586
end ,
1569
1587
extra_args = function (self , collection_name )
1588
+ if not self .settings .enable_mutations then
1589
+ return {}, {}
1590
+ end
1591
+
1570
1592
local collection = self .collections [collection_name ]
1571
1593
local schema_name = collection .schema_name
1572
1594
0 commit comments