@@ -1458,6 +1458,10 @@ end
1458
1458
--- ...
1459
1459
--- }
1460
1460
local function extra_args (self , collection_name )
1461
+ if not self .settings .enable_mutations then
1462
+ return {}, {}
1463
+ end
1464
+
1461
1465
local collection = self .collections [collection_name ]
1462
1466
local schema_name = collection .schema_name
1463
1467
@@ -1519,29 +1523,23 @@ end
1519
1523
--- Provided `funcs` argument determines certain functions for retrieving
1520
1524
--- tuples.
1521
1525
---
1522
- --- @tparam table opts `schemas`, `collections`, `service_fields`, `indexes` and
1523
- --- `collection_use_tomap` ({[collection_name] = whether objects in collection
1524
- --- collection_name intended to be unflattened using tuple:tomap({names_only = true})
1525
- --- method instead of compiled_avro_schema.unflatten(tuple), ...})
1526
- --- to give the data accessor all needed meta-information re data; the format is
1527
- --- shown below; additional attributes `resulting_object_cnt_max` and
1528
- --- `fetched_object_cnt_max` are optional positive numbers which help to control
1529
- --- query behaviour in case it requires more resources than expected _(default
1530
- --- value is 10,000)_; `timeout_ms` _(default is 1000)_
1531
- ---
1532
- --- @tparam table funcs set of functions:
1533
- ---
1534
- --- * `is_collection_exists`,
1535
- --- * `get_index`,
1536
- --- * `get_primary_index`,
1537
- --- * `unflatten_tuple`,
1538
- --- * `flatten_object`,
1539
- --- * `insert_tuple`.
1540
- ---
1541
- --- They allows this abstract data accessor behaves in the certain way (say,
1542
- --- like space data accessor or shard data accessor); consider the
1543
- --- `accessor_space` and the `accessor_shard` modules documentation for these
1544
- --- functions description.
1526
+ --- @tparam table opts set of options:
1527
+ ---
1528
+ --- * `schemas`,
1529
+ --- * `collections`,
1530
+ --- * `service_fields`,
1531
+ --- * `indexes`,
1532
+ --- * `collection_use_tomap`: ({[collection_name] = whether objects in
1533
+ --- collection `collection_name` intended to be unflattened using
1534
+ --- `tuple:tomap({names_only = true}` method instead of
1535
+ --- `compiled_avro_schema.unflatten(tuple), ...}`),
1536
+ --- * `resulting_object_cnt_max` and `fetched_object_cnt_max` are optional
1537
+ --- positive numbers which help to control query behaviour in case it
1538
+ --- requires more resources than expected _(default value is 10,000 for
1539
+ --- both)_,
1540
+ --- * `timeout_ms` _(default is 1000)_,
1541
+ --- * `enable_mutations`: boolean flag _(default is `false` for avro-schema-2*
1542
+ --- and `true` for avro-schema-3*)_.
1545
1543
---
1546
1544
--- For examples of `opts.schemas` and `opts.collections` consider the
1547
1545
--- @{tarantool_graphql.new} function description.
@@ -1568,6 +1566,20 @@ end
1568
1566
--- ...
1569
1567
--- }
1570
1568
---
1569
+ --- @tparam table funcs set of functions:
1570
+ ---
1571
+ --- * `is_collection_exists`,
1572
+ --- * `get_index`,
1573
+ --- * `get_primary_index`,
1574
+ --- * `unflatten_tuple`,
1575
+ --- * `flatten_object`,
1576
+ --- * `insert_tuple`.
1577
+ ---
1578
+ --- They allows this abstract data accessor behaves in the certain way (say,
1579
+ --- like space data accessor or shard data accessor); consider the
1580
+ --- `accessor_space` and the `accessor_shard` modules documentation for these
1581
+ --- functions description.
1582
+ ---
1571
1583
--- @treturn table data accessor instance, a table with the two methods
1572
1584
--- (`select` and `arguments`) as described in the @{tarantool_graphql.new}
1573
1585
--- function description.
@@ -1587,6 +1599,14 @@ function accessor_general.new(opts, funcs)
1587
1599
DEF_FETCHED_OBJECT_CNT_MAX
1588
1600
-- TODO: move this setting to `tgql.compile` after #59
1589
1601
local timeout_ms = opts .timeout_ms or DEF_TIMEOUT_MS
1602
+ -- Mutations are disabled for avro-schema-2*, because it can work
1603
+ -- incorrectly for schemas with nullable types.
1604
+ local enable_mutations
1605
+ if opts .enable_mutations == nil then
1606
+ enable_mutations = avro_helpers .major_avro_schema_version () == 3
1607
+ else
1608
+ enable_mutations = opts .enable_mutations
1609
+ end
1590
1610
1591
1611
assert (type (schemas ) == ' table' ,
1592
1612
' schemas must be a table, got ' .. type (schemas ))
@@ -1608,6 +1628,7 @@ function accessor_general.new(opts, funcs)
1608
1628
assert (timeout_ms <= TIMEOUT_INFINITY ,
1609
1629
(' timeouts more then graphql.TIMEOUT_INFINITY (%s) ' ..
1610
1630
' do not supported' ):format (tostring (TIMEOUT_INFINITY )))
1631
+ check (enable_mutations , ' enable_mutations' , ' boolean' )
1611
1632
1612
1633
local models , service_fields_defaults = compile_schemas (schemas ,
1613
1634
service_fields )
@@ -1637,7 +1658,8 @@ function accessor_general.new(opts, funcs)
1637
1658
settings = {
1638
1659
resulting_object_cnt_max = resulting_object_cnt_max ,
1639
1660
fetched_object_cnt_max = fetched_object_cnt_max ,
1640
- timeout_ms = timeout_ms
1661
+ timeout_ms = timeout_ms ,
1662
+ enable_mutations = enable_mutations ,
1641
1663
}
1642
1664
}, {
1643
1665
__index = {
0 commit comments