@@ -23,19 +23,30 @@ local tarantool_graphql = {}
23
23
local gql_type
24
24
25
25
local function avro_type (avro_schema )
26
- if type (avro_schema ) == ' table' and avro_schema .type == ' record' then
27
- return ' record'
28
- elseif type (avro_schema ) == ' table' and utils .is_array (avro_schema ) then
29
- return ' enum'
30
- elseif type (avro_schema ) == ' string' and avro_schema == ' int' then
31
- return ' int'
32
- elseif type (avro_schema ) == ' string' and avro_schema == ' long' then
33
- return ' long'
34
- elseif type (avro_schema ) == ' string' and avro_schema == ' string' then
35
- return ' string'
36
- else
37
- error (' unrecognized avro-schema type: ' .. json .encode (avro_schema ))
26
+ if type (avro_schema ) == ' table' then
27
+ if avro_schema .type == ' record' then
28
+ return ' record'
29
+ elseif avro_schema .type == ' record*' then
30
+ return ' record*'
31
+ elseif utils .is_array (avro_schema ) then
32
+ return ' union'
33
+ end
34
+ elseif type (avro_schema ) == ' string' then
35
+ if avro_schema == ' int' then
36
+ return ' int'
37
+ elseif avro_schema == ' int*' then
38
+ return ' int*'
39
+ elseif avro_schema == ' long' then
40
+ return ' long'
41
+ elseif avro_schema == ' long*' then
42
+ return ' long*'
43
+ elseif avro_schema == ' string' then
44
+ return ' string'
45
+ elseif avro_schema == ' string*' then
46
+ return ' string*'
47
+ end
38
48
end
49
+ error (' unrecognized avro-schema type: ' .. json .encode (avro_schema ))
39
50
end
40
51
41
52
-- XXX: recursive skip several NonNull's?
@@ -74,10 +85,16 @@ local function convert_scalar_type(avro_schema, opts)
74
85
local avro_t = avro_type (avro_schema )
75
86
if avro_t == ' int' then
76
87
return types .int .nonNull
88
+ elseif avro_t == ' int*' then
89
+ return types .int
77
90
elseif avro_t == ' long' then
78
91
return types_long .nonNull
92
+ elseif avro_t == ' long*' then
93
+ return types_long
79
94
elseif avro_t == ' string' then
80
95
return types .string .nonNull
96
+ elseif avro_t == ' string*' then
97
+ return types .string
81
98
end
82
99
if raise then
83
100
error (' unrecognized avro-schema scalar type: ' ..
@@ -201,7 +218,9 @@ gql_type = function(state, avro_schema, collection, collection_name)
201
218
assert (accessor .list_args ~= nil ,
202
219
' state.accessor.list_args must not be nil' )
203
220
204
- if avro_type (avro_schema ) == ' record' then
221
+ local avro_t = avro_type (avro_schema )
222
+
223
+ if avro_t == ' record' or avro_t == ' record*' then
205
224
assert (type (avro_schema .name ) == ' string' ,
206
225
(' avro_schema.name must be a string, got %s (avro_schema %s)' )
207
226
:format (type (avro_schema .name ), json .encode (avro_schema )))
@@ -299,15 +318,14 @@ gql_type = function(state, avro_schema, collection, collection_name)
299
318
}
300
319
end
301
320
302
- local res = types .nonNull ( types . object ({
321
+ local res = types .object ({
303
322
name = collection ~= nil and collection .name or avro_schema .name ,
304
323
description = ' generated from avro-schema for ' ..
305
324
avro_schema .name ,
306
325
fields = fields ,
307
- }))
308
-
309
- return res
310
- elseif avro_type (avro_schema ) == ' enum' then
326
+ })
327
+ return avro_t == ' record' and types .nonNull (res ) or res
328
+ elseif avro_t == ' enum' then
311
329
error (' enums not implemented yet' ) -- XXX
312
330
else
313
331
local res = convert_scalar_type (avro_schema , {raise = false })
0 commit comments