-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
eca0b2b
to
e9887a5
Compare
@Khatskevich @SudoBobo The PR is ready for review. |
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.
First phase, but not the last...
assert(c.type == '1:1' or c.type == '1:N', | ||
'connection.type must be 1:1 or 1:N, got ' .. c.type) | ||
assert(c.type == '1:1' or c.type == '1:1*' or c.type == '1:N', | ||
'connection.type must be 1:1, 1:1* or 1:N, got ' .. c.type) |
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.
I do not like * syntax. It looks like magic for the person who see it the first time
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.
Additional field (nullable=true) would also simplify your code. Because now 1:1 and 1:1* are generally the same, but you check both
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.
I want to be consistent with our extended avro-schema approach.
graphql/tarantool_graphql.lua
Outdated
@@ -253,7 +253,7 @@ end | |||
--- The function converts passed avro-schema to a GraphQL type. | |||
--- | |||
--- @tparam table state for read state.accessor and previously filled | |||
--- state.types (state.types are gql types) | |||
--- state.nullable_collection_types (its are gql types) |
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.
Those are
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.
Fixed.
@@ -230,7 +230,7 @@ end | |||
--- Convert each field of an avro-schema to a graphql type. | |||
--- | |||
--- @tparam table state for read state.accessor and previously filled | |||
--- state.types | |||
--- state.nullable_collection_types |
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.
Why do you rename it?
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.
I generally against common words to refer specific things. This field contains only collection types (and does not contain, say, nested records) and that types converted to nullable ones (because of lazy types evaluation, consider comments). So more specific name nullable_collection_types
is fair term for that. Maybe collection_types_nullable
is better, though.
graphql/tarantool_graphql.lua
Outdated
assert(destination_type ~= nil, | ||
('destination_type (named %s) must not be nil'):format( | ||
c.destination_collection)) | ||
|
||
local c_args | ||
if c.type == '1:1' then | ||
destination_type = types.nonNull( | ||
state.nullable_collection_types[c.destination_collection]) |
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.
Why you do not reuse destination type?
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.
You can make collection nonnull 2 times? I do not understand completely what would happen in this case.
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.
- Fixed.
- I’m sure that collection types are nullable because it is how I save it.
@@ -405,7 +450,7 @@ gql_type = function(state, avro_schema, collection, collection_name) | |||
avro_schema.name, | |||
fields = fields, | |||
}) | |||
return avro_t == 'enum' and types.nonNull(res) or res | |||
return avro_t == 'record' and types.nonNull(res) or res |
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.
May be I am wrong, but I suppose that if the type is nullable or not should decide type user, but not type itself.
I suggest always return nullable types.
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.
Interesting idea, but it would be architectural change. It is smth that we can have in our minds to consider. Thanks!
end | ||
|
||
results = results .. print_and_return(([[ | ||
+---------------------+ |
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.
What is that?) Why do you print it? Moreover it is not printed in shard tests. Better to just leave it as a comment?
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.
Forgot to print in shard tests. Will do. It was for convenient investigation of run of the test.
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.
Consider yaml module in tarantool:
third_party/lua-yaml/lyaml.cc
} else if (strstr(str, "\n\n") != NULL) {
/*
* Tarantool-specific: use literal style for string with empty lines.
* Useful for tutorial().
*/
style = YAML_LITERAL_SCALAR_STYLE;
}
I added two newlines in the begin of the string and got right output for the shard tests.
@@ -0,0 +1,398 @@ | |||
-- The example was inspired by [1]. Consider [2] for the problem description |
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.
It is up to you, but I do not like those teste. In my opinion we need to:
- Write common tests
- Check results in tests
Pros:
- To validate test results we do not need to read 3 result files
- The code you copy can contain small bugs, so, it should also be read 3 times
It is just a waste of time!
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.
I think I should work on reducing code size of the tests. Maybe I should consider 'common' test suite + tap13, but I want to: run local test as just file, don’t repeat the sime initialization / running steps, working shard module reloading. I’ll consider your pain at reading in the next PRs.
59e28ff
to
f79bdaf
Compare
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.
I request some important changes.
See comments.
value | ||
|
||
if value ~= nil then -- nil or box.NULL | ||
are_all_parts_null = false |
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.
I suppose this code should be moved outside of the closure (as a call to a function)
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.
I’ll think about that before merge, but I’ll skip it now. Thanks for the point.
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.
graphql/tarantool_graphql.lua
Outdated
local is_full_match_ok = are_all_parts_null or | ||
are_all_parts_non_null | ||
if not is_full_match_ok then -- avoid extra json.encode() | ||
assert(is_full_match_ok, |
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.
Delete if, it is useless because your assert contains the same condition
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.
Please, read the comment for this if.
graphql/tarantool_graphql.lua
Outdated
-- key parts | ||
-- | ||
-- zero parts count considered as ok by this check | ||
local is_full_match_ok = are_all_parts_null or |
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.
I do not like the extra variable with the strange name is_full_match_ok
. It does not increase readability and should be used only once in the following assert, please, use just are_all_parts_null or are_all_parts_non_null
instead (in assert).
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.
Ok, I’ll use name ok
. Don’t want to carry lines, it looks ugly here.
graphql/tarantool_graphql.lua
Outdated
-- return the empty list. | ||
if are_all_parts_null then | ||
assert(c.type == '1:1*' or c.type == '1:N', | ||
'only 1:1* or 1:N connections can have ' .. |
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.
Do not split the user-visible output into lines (grep). We should follow this rule in the future too.
To maintain good code style, I propose to create a file with error messages.
Moreover, in this particular case, I believe you should provide extra information about the failed object. Because even after user sees this error, it is impossible to debug the case.
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.
We discussed the line carrying in the case in context of tarantool code style and decided to force formal line lenght limit. So I’ll prefer to fit the limit, but I’ll try to split a message by meaningful parts.
extra info: TBD
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.
extra info: added
graphql/tarantool_graphql.lua
Outdated
end | ||
|
||
-- check FULL match constraint before request of | ||
-- destination object(s) |
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.
Half of your comments are sentences with a dot at the end and start with a capital teller, and half of them are just text. I like the first option more. Let's follow the style?
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.
My approach is the following. I use small letter in the begin and omit period at the end when the comment is one clause or like so (maybe even an expanded sentence, but only one). Several sentences started from capital letter and have period at the end.
Here we have several sentences, so I reformatted this into one multi-sentence comment (capital letter + period).
|
||
local function new_email(body) | ||
return { | ||
localpart = random_string(16):hex(), |
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.
Please, do not use random functions for pest data. This field can not be used in test output because it is not consistent.
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.
I initialized PRNG with a constant seed. You can use it in the output and it will be the same.
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.
Found that math.random() gives different numbers on different machines. Implemented simple PRNG in the test.
end) | ||
|
||
-- FULL MATCH constraint: connection key parts must be all non-nulls or all | ||
-- nulls |
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.
Please, create 1 failing test.
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.
I have two failing tests here. Commented explicitly that they are fails.
d7eab2c
to
291cf7e
Compare
Fixes #44.
291cf7e
to
13c5c7b
Compare
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.
Everything is negotiated or fixed. ACK
Fixes #44.