This repository was archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Sb/avro arr #48
Closed
Closed
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 417c83e
do small refactor; add comments
SudoBobo 24ec6c4
add support for array avro type (only with scalars); change args
SudoBobo 9a43096
simplify conditional statements
SudoBobo 6bd1ca2
add mised simple test for array support
SudoBobo 31897d6
add simple test for array avro type usage
SudoBobo f0fb9f4
move nullable function to utils as it is will be
SudoBobo ac9f0ed
readability refactor; clean up comments;
SudoBobo 8110208
Update tarantool_graphql.lua
SudoBobo f50f9fc
Merge remote-tracking branch 'origin/sb/avro_arr' into sb/avro_arr
SudoBobo 043d6f9
small style fixes
SudoBobo 7714393
readability and comments fixes
SudoBobo 470e8e1
remove excess test
SudoBobo 0160c69
remove redundant 'map' test cases
SudoBobo 19b8d8b
fix small error; now general convert_scalar_type accepts nil as opt
SudoBobo 1377c75
add test for avro-array usage (with space accessor);
SudoBobo 5af08d8
move nullable back to tarantool_graphql from utils
SudoBobo be8457c
add support of avro map and test for simple case with scalar map values
SudoBobo fec3b31
add test for map with space accessor
SudoBobo 0423ec4
add gql support of avro map/array with records as items/values
SudoBobo a936771
style/readability fixes after review
SudoBobo c8abf95
remove executable bit
SudoBobo 951e7ea
add info about Map
SudoBobo 91bd8bf
typo fix
SudoBobo 148f69f
Merge branch 'master' into sb/avro_arr
SudoBobo d9a7623
remove whitespaces at the end of lines
SudoBobo 31abefa
Merge remote-tracking branch 'origin/sb/avro_arr' into sb/avro_arr
SudoBobo 1f2583a
remove all debug prints
SudoBobo e406a31
make Map and Object explanation more specific
SudoBobo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
... | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
RESULT | ||
--- | ||
user_collection: | ||
- user_id: def | ||
favorite_food: | ||
- meat | ||
- potato | ||
... | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' .. ';' .. | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
... | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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