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

[WIP] Sb/avro arr #48

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
589778a
add comments on gql queries assert and compile functions
SudoBobo Feb 19, 2018
417c83e
do small refactor; add comments
SudoBobo Feb 20, 2018
24ec6c4
add support for array avro type (only with scalars); change args
SudoBobo Feb 21, 2018
9a43096
simplify conditional statements
SudoBobo Feb 22, 2018
6bd1ca2
add mised simple test for array support
SudoBobo Feb 22, 2018
31897d6
add simple test for array avro type usage
SudoBobo Feb 23, 2018
f0fb9f4
move nullable function to utils as it is will be
SudoBobo Feb 23, 2018
ac9f0ed
readability refactor; clean up comments;
SudoBobo Feb 23, 2018
8110208
Update tarantool_graphql.lua
SudoBobo Feb 23, 2018
f50f9fc
Merge remote-tracking branch 'origin/sb/avro_arr' into sb/avro_arr
SudoBobo Feb 24, 2018
043d6f9
small style fixes
SudoBobo Feb 25, 2018
7714393
readability and comments fixes
SudoBobo Feb 26, 2018
470e8e1
remove excess test
SudoBobo Feb 26, 2018
0160c69
remove redundant 'map' test cases
SudoBobo Feb 26, 2018
19b8d8b
fix small error; now general convert_scalar_type accepts nil as opt
SudoBobo Feb 26, 2018
1377c75
add test for avro-array usage (with space accessor);
SudoBobo Feb 26, 2018
5af08d8
move nullable back to tarantool_graphql from utils
SudoBobo Feb 26, 2018
be8457c
add support of avro map and test for simple case with scalar map values
SudoBobo Feb 27, 2018
fec3b31
add test for map with space accessor
SudoBobo Feb 27, 2018
0423ec4
add gql support of avro map/array with records as items/values
SudoBobo Feb 28, 2018
a936771
style/readability fixes after review
SudoBobo Feb 28, 2018
c8abf95
remove executable bit
SudoBobo Feb 28, 2018
951e7ea
add info about Map
SudoBobo Feb 28, 2018
91bd8bf
typo fix
SudoBobo Feb 28, 2018
148f69f
Merge branch 'master' into sb/avro_arr
SudoBobo Feb 28, 2018
d9a7623
remove whitespaces at the end of lines
SudoBobo Feb 28, 2018
31abefa
Merge remote-tracking branch 'origin/sb/avro_arr' into sb/avro_arr
SudoBobo Feb 28, 2018
1f2583a
remove all debug prints
SudoBobo Feb 28, 2018
e406a31
make Map and Object explanation more specific
SudoBobo Feb 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 133 additions & 21 deletions graphql/tarantool_graphql.lua

Large diffs are not rendered by default.

Empty file modified graphql/utils.lua
100644 → 100755
Empty file.
14 changes: 14 additions & 0 deletions test/local/array_and_map_space_accessor.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RESULT
---
user_collection:
- favorite_holidays: {'december': 'new year', 'march': 'vacation'}
user_id: user_id_1
user_balances:
- value: 33
- value: 44
favorite_food:
- meat
- potato
customer_balances: {'salary': {'value': 333}, 'deposit': {'value': 444}}
...

65 changes: 65 additions & 0 deletions test/local/array_and_map_space_accessor.test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env tarantool

box.cfg { background = false }
local fio = require('fio')

-- require in-repo version of graphql/ sources despite current working directory
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path

local graphql = require('graphql')
local testdata = require('test.testdata.array_and_map_testdata')

-- init box, upload test data and acquire metadata
-- -----------------------------------------------


-- init box and data schema
testdata.init_spaces()

-- upload test data
testdata.fill_test_data()

-- acquire metadata
local metadata = testdata.get_test_metadata()
local schemas = metadata.schemas
local collections = metadata.collections
local service_fields = metadata.service_fields
local indexes = metadata.indexes
local utils = require('graphql.utils')

-- build accessor and graphql schemas
-- ----------------------------------
local accessor
utils.show_trace(
function()
accessor = graphql.accessor_space.new({
schemas = schemas,
collections = collections,
service_fields = service_fields,
indexes = indexes,
})
end
)

local gql_wrapper
utils.show_trace(function()
gql_wrapper = graphql.new({
schemas = schemas,
collections = collections,
accessor = accessor,
})
end
)

-- run queries
-- -----------

testdata.run_queries(gql_wrapper)

-- clean up
-- --------

testdata.drop_spaces()

os.exit()
9 changes: 9 additions & 0 deletions test/local/simple_avro_array.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RESULT
---
user_collection:
- user_id: def
favorite_food:
- meat
- potato
...

98 changes: 98 additions & 0 deletions test/local/simple_avro_array.test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env tarantool

local fio = require('fio')

--require in-repo version of graphql/ sources despite current working directory
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent is even stranger then in the test before :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that was produced by my IDE. Fixed that

package.path


local json = require('json')
local yaml = require('yaml')
local graphql = require('graphql')
local utils = require('graphql.utils')

local schemas = json.decode([[{
"user": {
"name": "user",
"type": "record",
"fields": [
{ "name": "user_id", "type": "string" },
{ "name": "favorite_food", "type": {"type": "array", "items": "string"} }
]
}
}]])

local collections = json.decode([[{
"user_collection": {
"schema_name": "user"
}
}]])

local function simple_access_function(parent, collection_name, filter, args)
--[[
print('DEBUG: collection_name: ' .. collection_name)
print('DEBUG: filter: ' .. json.encode(filter))
print('DEBUG: args: ' .. json.encode(args))
print('DEBUG: --------')
--]]
local obj
if collection_name == 'user_collection' then
obj = {
user_id = 'def',
favorite_food = { 'meat', 'potato' },
}
else
error('NIY: ' .. collection_name)
end
if not utils.is_subtable(obj, filter) then
return {}
end
return { obj }
end

local simple_accessor = setmetatable({}, {
__index = {
select = function(self, parent, collection_name, connection_name,
filter, args)
return simple_access_function(parent, collection_name, filter, args)
end,
list_args = function(self, connection_type)
if connection_type == '1:1' then
return {}
end
return {
{ name = 'limit', type = 'int' },
{ name = 'offset', type = 'long' },
-- {name = 'filter', type = ...},
}
end,
}
})

local gql_wrapper_simple_accessor = graphql.new({
-- class_name:class mapping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 space indent is needed here.

schemas = schemas,
-- collection_{schema_name=..., connections=...} mapping
collections = collections,
-- :select() and :list_args() provider
accessor = simple_accessor,
})

local query_with_list = [[
query userFavs($user_id: String) {
user_collection(user_id: $user_id) {
user_id
favorite_food
}
}
]]

utils.show_trace(function()
local variables_2 = { user_id = 'def' }
local gql_query_2 = gql_wrapper_simple_accessor:compile(query_with_list)
local result = gql_query_2:execute(variables_2)
print(('RESULT\n%s'):format(yaml.encode(result)))
end)

9 changes: 9 additions & 0 deletions test/local/simple_avro_map.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RESULT
---
user_collection:
- user_id: def
favorite_holidays:
december: new year
march: vacation
...

102 changes: 102 additions & 0 deletions test/local/simple_avro_map.test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env tarantool

local fio = require('fio')

--require in-repo version of graphql/ sources despite current working directory
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' ..
package.path

local json = require('json')
local yaml = require('yaml')
local graphql = require('graphql')
local utils = require('graphql.utils')

local schemas = json.decode([[{
"user": {
"name": "user",
"type": "record",
"fields": [
{ "name": "user_id", "type": "string" },
{ "name": "favorite_holidays", "type": {"type": "map", "values": "string"} }
]
}
}]])

local collections = json.decode([[{
"user_collection": {
"schema_name": "user"
}
}]])

local function simple_access_function(parent, collection_name, filter, args)
--[[
print('DEBUG: collection_name: ' .. collection_name)
print('DEBUG: filter: ' .. json.encode(filter))
print('DEBUG: args: ' .. json.encode(args))
print('DEBUG: --------')
--]]
local obj
if collection_name == 'user_collection' then
obj = {
user_id = 'def',
favorite_holidays = { december = 'new year', march = 'vacation' }
}
else
error('NIY: ' .. collection_name)
end
if not utils.is_subtable(obj, filter) then
return {}
end
return { obj }
end

local simple_accessor = setmetatable({}, {
__index = {
select = function(self, parent, collection_name, connection_name,
filter, args)
return simple_access_function(parent, collection_name, filter, args)
end,
list_args = function(self, connection_type)
if connection_type == '1:1' then
return {}
end
return {
{ name = 'limit', type = 'int' },
{ name = 'offset', type = 'long' },
-- {name = 'filter', type = ...},
}
end,
}
})

local gql_wrapper_simple_accessor
local query_with_map
utils.show_trace(function()
gql_wrapper_simple_accessor = graphql.new({
-- class_name:class mapping
schemas = schemas,
-- collection_{schema_name=..., connections=...} mapping
collections = collections,
-- :select() and :list_args() provider
accessor = simple_accessor,
})

query_with_map = [[
query userFavs($user_id: String) {
user_collection(user_id: $user_id) {
user_id
favorite_holidays
}
}
]]

end
)

utils.show_trace(function()
local variables_2 = { user_id = 'def' }
local gql_query_2 = gql_wrapper_simple_accessor:compile(query_with_map)
local result = gql_query_2:execute(variables_2)
print(('RESULT\n%s'):format(yaml.encode(result)))
end)
Loading