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

Commit 320e98e

Browse files
committed
Move our own types to graphql/core/types.lua
Part of #166.
1 parent 5eb048b commit 320e98e

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

graphql/core/types.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ function types.union(config)
171171
return instance
172172
end
173173

174+
types.map = types.scalar({
175+
name = 'Map',
176+
description = 'Map is a dictionary with string keys and values of ' ..
177+
'arbitrary but same among all values type',
178+
serialize = function(value) return value end,
179+
parseValue = function(value) return value end,
180+
parseLiteral = function(node)
181+
if node.kind == 'Map' then
182+
return node.value
183+
end
184+
end
185+
})
186+
174187
function types.inputObject(config)
175188
assert(type(config.name) == 'string', 'type name must be provided as a string')
176189

@@ -215,6 +228,19 @@ types.int = types.scalar({
215228
end
216229
})
217230

231+
types.long = types.scalar({
232+
name = 'Long',
233+
description = 'Long is non-bounded integral type',
234+
serialize = function(value) return tonumber(value) end,
235+
parseValue = function(value) return tonumber(value) end,
236+
parseLiteral = function(node)
237+
-- 'int' is name of the immediate value type
238+
if node.kind == 'int' then
239+
return tonumber(node.value)
240+
end
241+
end
242+
})
243+
218244
types.float = types.scalar({
219245
name = 'Float',
220246
serialize = tonumber,
@@ -226,6 +252,18 @@ types.float = types.scalar({
226252
end
227253
})
228254

255+
types.double = types.scalar({
256+
name = 'Double',
257+
serialize = tonumber,
258+
parseValue = tonumber,
259+
parseLiteral = function(node)
260+
-- 'float' and 'int' are names of immediate value types
261+
if node.kind == 'float' or node.kind == 'int' then
262+
return tonumber(node.value)
263+
end
264+
end
265+
})
266+
229267
types.string = types.scalar({
230268
name = 'String',
231269
description = "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.",

graphql/tarantool_graphql.lua

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,44 +156,6 @@ local function raw_gql_type(gql_class)
156156
return gql_class
157157
end
158158

159-
local types_long = types.scalar({
160-
name = 'Long',
161-
description = 'Long is non-bounded integral type',
162-
serialize = function(value) return tonumber(value) end,
163-
parseValue = function(value) return tonumber(value) end,
164-
parseLiteral = function(node)
165-
-- 'int' is name of the immediate value type
166-
if node.kind == 'int' then
167-
return tonumber(node.value)
168-
end
169-
end
170-
})
171-
172-
local types_double = types.scalar({
173-
name = 'Double',
174-
serialize = tonumber,
175-
parseValue = tonumber,
176-
parseLiteral = function(node)
177-
-- 'float' and 'int' are names of immediate value types
178-
if node.kind == 'float' or node.kind == 'int' then
179-
return tonumber(node.value)
180-
end
181-
end
182-
})
183-
184-
local types_map = types.scalar({
185-
name = 'Map',
186-
description = 'Map is a dictionary with string keys and values of ' ..
187-
'arbitrary but same among all values type',
188-
serialize = function(value) return value end,
189-
parseValue = function(value) return value end,
190-
parseLiteral = function(node)
191-
if node.kind == 'Map' then
192-
return node.value
193-
end
194-
end
195-
})
196-
197159
local function convert_scalar_type(avro_schema, opts)
198160
local opts = opts or {}
199161
assert(type(opts) == 'table', 'opts must be nil or table, got ' ..
@@ -205,12 +167,12 @@ local function convert_scalar_type(avro_schema, opts)
205167
local scalar_types = {
206168
['int'] = types.int.nonNull,
207169
['int*'] = types.int,
208-
['long'] = types_long.nonNull,
209-
['long*'] = types_long,
170+
['long'] = types.long.nonNull,
171+
['long*'] = types.long,
210172
['float'] = types.float.nonNull,
211173
['float*'] = types.float,
212-
['double'] = types_double.nonNull,
213-
['double*'] = types_double,
174+
['double'] = types.double.nonNull,
175+
['double*'] = types.double,
214176
['boolean'] = types.boolean.nonNull,
215177
['boolean*'] = types.boolean,
216178
['string'] = types.string.nonNull,
@@ -1274,7 +1236,7 @@ gql_type = function(state, avro_schema, context)
12741236
-- validate avro schema format inside 'values'
12751237
gql_type(state, avro_schema.values, context)
12761238

1277-
local gql_map = types_map
1239+
local gql_map = types.map
12781240
return avro_t == 'map' and types.nonNull(gql_map) or gql_map
12791241
elseif avro_t == 'union' then
12801242
return create_gql_union(state, avro_schema, context)

0 commit comments

Comments
 (0)