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

Commit b3c1b85

Browse files
committed
Minor style fixes after array/map support
1 parent 21889b7 commit b3c1b85

5 files changed

+32
-34
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ sharded using tarantool/shard module.
5252
User should distinguish between Object and Map types. Both of them consists of
5353
keys and values but there are some important differences.
5454

55-
While Object is a GraphQL
56-
built-in type, Map is a scalar-based type. In case of Object-based type
57-
all key-value pairs are set during type definition and values may have
58-
different types (as defined in the schema).
55+
While Object is a GraphQL built-in type, Map is a scalar-based type. In case of
56+
Object-based type all key-value pairs are set during type definition and values
57+
may have different types (as defined in the schema).
5958

6059
In contrast, set of valid Map keys is not defined in the schema, any key-value
6160
pair is valid despite name of the key while value has schema-determined type
@@ -64,8 +63,8 @@ pair is valid despite name of the key while value has schema-determined type
6463
Map-based types should be queried as a scalar type, not as an object type
6564
(because map's keys are not part of the schema).
6665

66+
The following example works:
6767

68-
This works
6968
```
7069
{
7170
@@ -74,7 +73,8 @@ This works
7473
}
7574
```
7675

77-
This doesn't work
76+
The following example doesn't work:
77+
7878
```
7979
{
8080
@@ -84,6 +84,7 @@ This doesn't work
8484
8585
}
8686
```
87+
8788
## Run tests
8889

8990
```
@@ -94,7 +95,7 @@ make test
9495

9596
## Requirements
9697

97-
* For use: tarantool, lulpeg, >=tarantool/shard-1.1-91-gfa88bf8 (optional),
98+
* For use: tarantool, lulpeg, >=tarantool/shard-1.1-91-gfa88bf8 (optional),
9899
tarantool/avro-schema.
99100
* For test (additionally to 'for use'): python 2.7, virtualenv, luacheck.
100101
* For building apidoc (additionally to 'for use'): ldoc.

graphql/tarantool_graphql.lua

+9-7
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ local types_map = types.scalar({
8585
description = 'Map is a dictionary with string keys and values of ' ..
8686
'arbitrary but same among all values type',
8787
serialize = function(value) return value end,
88-
parseValue = function(value)return value end,
89-
-- node == ast
88+
parseValue = function(value) return value end,
9089
parseLiteral = function(node)
9190
if node.kind == 'Map' then
9291
return node.value
@@ -129,10 +128,11 @@ end
129128

130129
--- Non-recursive version of the @{gql_type} function that returns
131130
--- InputObject instead of Object.
131+
---
132132
--- An error will be raised if avro_schema type is 'record'
133-
--- and its' fields are not scalar type because currently
134-
--- triple nesting level (record with record as a field - ok,
135-
--- record with record which has inside another level - not ok).
133+
--- and its' fields have non-scalar types. So triple nesting level is not
134+
--- supported (record with record as a field - ok, record with record which
135+
--- has inside an another level - not ok).
136136
local function gql_argument_type(avro_schema)
137137
assert(avro_schema ~= nil,
138138
'avro_schema must not be nil')
@@ -267,7 +267,7 @@ end
267267
---
268268
--- XXX As it is not clear now what to do with complex types inside arrays
269269
--- (just pass to results or allow to use filters), only scalar arrays
270-
--- is allowed for now.
270+
--- is allowed for now. Note: map is considered scalar.
271271
gql_type = function(state, avro_schema, collection, collection_name)
272272
assert(type(state) == 'table',
273273
'state must be a table, got ' .. type(state))
@@ -424,11 +424,13 @@ gql_type = function(state, avro_schema, collection, collection_name)
424424
'values must not be nil in map avro schema')
425425
assert(type(avro_schema.values) == 'table'
426426
or type(avro_schema.values) == 'string',
427-
('avro_schema.values must be a table or a string,' ..
427+
('avro_schema.values must be a table or a string, ' ..
428428
'got %s (avro_schema %s)'):format(type(avro_schema.values),
429429
json.encode(avro_schema)))
430430

431+
-- validate avro schema format inside 'values'
431432
gql_type(state, avro_schema.values)
433+
432434
local gql_map = types_map
433435
return avro_t == 'map' and types.nonNull(gql_map) or gql_map
434436
else

test/local/array_and_map_space_accessor.test.lua

+6-11
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,22 @@ local utils = require('graphql.utils')
3030

3131
-- build accessor and graphql schemas
3232
-- ----------------------------------
33-
local accessor
34-
utils.show_trace(
35-
function()
36-
accessor = graphql.accessor_space.new({
33+
local accessor = utils.show_trace(function()
34+
return graphql.accessor_space.new({
3735
schemas = schemas,
3836
collections = collections,
3937
service_fields = service_fields,
4038
indexes = indexes,
4139
})
42-
end
43-
)
40+
end)
4441

45-
local gql_wrapper
46-
utils.show_trace(function()
47-
gql_wrapper = graphql.new({
42+
local gql_wrapper = utils.show_trace(function()
43+
return graphql.new({
4844
schemas = schemas,
4945
collections = collections,
5046
accessor = accessor,
5147
})
52-
end
53-
)
48+
end)
5449

5550
-- run queries
5651
-- -----------

test/local/simple_avro_array.test.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local fio = require('fio')
66
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
77
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
88

9-
109
local json = require('json')
1110
local yaml = require('yaml')
1211
local graphql = require('graphql')
@@ -20,8 +19,8 @@ local schemas = json.decode([[{
2019
{ "name": "user_id", "type": "string" },
2120
{ "name": "favorite_food", "type": {"type": "array", "items": "string"} }
2221
]
23-
}
24-
}]])
22+
}
23+
}]])
2524

2625
local collections = json.decode([[{
2726
"user_collection": {
@@ -95,3 +94,4 @@ utils.show_trace(function()
9594
print(('RESULT\n%s'):format(yaml.encode(result)))
9695
end)
9796

97+
os.exit()

test/local/simple_avro_map.test.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ local gql_wrapper_simple_accessor
7474
local query_with_map
7575
utils.show_trace(function()
7676
gql_wrapper_simple_accessor = graphql.new({
77-
-- class_name:class mapping
77+
-- class_name:class mapping
7878
schemas = schemas,
79-
-- collection_{schema_name=..., connections=...} mapping
79+
-- collection_{schema_name=..., connections=...} mapping
8080
collections = collections,
81-
-- :select() and :list_args() provider
81+
-- :select() and :list_args() provider
8282
accessor = simple_accessor,
8383
})
8484

@@ -90,13 +90,13 @@ utils.show_trace(function()
9090
}
9191
}
9292
]]
93-
94-
end
95-
)
93+
end)
9694

9795
utils.show_trace(function()
9896
local variables_2 = { user_id = 'def' }
9997
local gql_query_2 = gql_wrapper_simple_accessor:compile(query_with_map)
10098
local result = gql_query_2:execute(variables_2)
10199
print(('RESULT\n%s'):format(yaml.encode(result)))
102100
end)
101+
102+
os.exit()

0 commit comments

Comments
 (0)