-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Sb/avro arr #48
Changes from 25 commits
589778a
417c83e
24ec6c4
9a43096
6bd1ca2
31897d6
f0fb9f4
ac9f0ed
8110208
f50f9fc
043d6f9
7714393
470e8e1
0160c69
19b8d8b
1377c75
5af08d8
be8457c
fec3b31
0423ec4
a936771
c8abf95
951e7ea
91bd8bf
148f69f
d9a7623
31abefa
1f2583a
e406a31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,42 @@ GraphQL queries on data from the local Tarantool's storage called spaces. | |
It is planned to implement another data accessor that allows to fetch objects | ||
sharded using tarantool/shard module. | ||
|
||
### Notes on types | ||
|
||
User should distinguish between Object and Map types. Both of them consists of | ||
keys and values but there are some important differences. | ||
|
||
While Object is a GraphQL | ||
built-in type, Map is a scalar-based type. In case of Object-based type | ||
all key-value pairs are set during type definition and values may have different | ||
arbitrary types. | ||
|
||
In contrast, all values of Map-based type must have the same | ||
type and specific key-value pairs are not set during type definition. | ||
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. specific key-value pairs are not set during type definition → set of valid keys is not defined in the schema, any key-value pair is valid despite name of the key while value has schema-determined type; what do you think? 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. set of valid keys is not defined in the schema, any key-value pair is valid despite name of the key while value has schema-determined type (which is the same among all values in the map) ? 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. Ok. |
||
|
||
Map-based types should be queried as a scalar type, not as an object type | ||
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.
|
||
(because map's keys are not part of the schema) | ||
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. Period at the end. |
||
|
||
|
||
This works | ||
``` | ||
{ | ||
… | ||
map_based_type | ||
… | ||
} | ||
``` | ||
|
||
This doesn't work | ||
``` | ||
{ | ||
… | ||
map_based_type { | ||
key_1 | ||
} | ||
… | ||
} | ||
``` | ||
## Run tests | ||
|
||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,13 @@ local function mergeSelectionSets(fields) | |
end | ||
|
||
local function defaultResolver(object, arguments, info) | ||
--print('print from default resolver in execute 82 ') | ||
--print(object) | ||
--require('pl.pretty').dump(object) | ||
--require('pl.pretty').dump(object) | ||
--print('print from default resolver in 86') | ||
--require('pl.pretty').dump(info.fieldASTs[1].name.value) | ||
--require('pl.pretty').dump(object[info.fieldASTs[1].name.value]) | ||
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. Forgotten debug. |
||
return object[info.fieldASTs[1].name.value] | ||
end | ||
|
||
|
@@ -148,6 +155,25 @@ end | |
|
||
local evaluateSelections | ||
|
||
--- check if given object is flat and have only scalars | ||
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. If you want to add ldoc comment, then use it's convention: start short function description with a capital letter and end it with a period. Otherwise, use a regular comment ( |
||
local function is_simple_object(object) | ||
assert(type(object) == 'table', 'object type must be table') | ||
|
||
for _, v in pairs(object) do | ||
if type(v) == 'table' or type(v) == 'function' then | ||
return false | ||
end | ||
end | ||
|
||
for _, v in ipairs(object) do | ||
if type(v) == 'table' or type(v) == 'function' then | ||
return false | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
local function completeValue(fieldType, result, subSelections, context) | ||
local fieldTypeName = fieldType.__type | ||
|
||
|
@@ -166,6 +192,7 @@ local function completeValue(fieldType, result, subSelections, context) | |
return nil | ||
end | ||
|
||
|
||
if fieldTypeName == 'List' then | ||
local innerType = fieldType.ofType | ||
|
||
|
@@ -175,7 +202,21 @@ local function completeValue(fieldType, result, subSelections, context) | |
|
||
local values = {} | ||
for i, value in ipairs(result) do | ||
--print('print from List section in completeValue() 182 with i == ' .. i) | ||
--print('INNER TYPE') | ||
--require('pl.pretty').dump(innerType) | ||
--print('VALUE') | ||
--require('pl.pretty').dump(value) | ||
-- | ||
--print("is simple object?") | ||
--print(is_simple_object(value)) | ||
|
||
--values[i] = is_simple_object(value) and value or | ||
-- completeValue(innerType, value, subSelections, context) | ||
values[i] = completeValue(innerType, value, subSelections, context) | ||
--print('result after completeValue()') | ||
--require('pl.pretty').dump(value[i]) | ||
|
||
end | ||
|
||
return next(values) and values or context.schema.__emptyList | ||
|
@@ -186,6 +227,9 @@ local function completeValue(fieldType, result, subSelections, context) | |
end | ||
|
||
if fieldTypeName == 'Object' then | ||
-- можно добавить условие, что если объект простой | ||
-- и вложенностей нет | ||
-- то вернуть его как есть и не делать evaluateSelections | ||
local fields = evaluateSelections(fieldType, result, subSelections, context) | ||
return next(fields) and fields or context.schema.__emptyObject | ||
elseif fieldTypeName == 'Interface' or fieldTypeName == 'Union' then | ||
|
@@ -197,10 +241,17 @@ local function completeValue(fieldType, result, subSelections, context) | |
end | ||
|
||
local function getFieldEntry(objectType, object, fields, context) | ||
|
||
--print('print from 242 execute lua') | ||
|
||
local firstField = fields[1] | ||
local fieldName = firstField.name.value | ||
local responseKey = getFieldResponseKey(firstField) | ||
local fieldType = introspection.fieldMap[fieldName] or objectType.fields[fieldName] | ||
-- | ||
--require('pl.pretty').dump(fieldName) | ||
--require('pl.pretty').dump(fieldType) | ||
|
||
|
||
if fieldType == nil then | ||
return nil | ||
|
@@ -231,25 +282,53 @@ local function getFieldEntry(objectType, object, fields, context) | |
|
||
local resolvedObject = (fieldType.resolve or defaultResolver)(object, arguments, info) | ||
local subSelections = mergeSelectionSets(fields) | ||
--print('print from 258 in execute') | ||
--require('pl.pretty').dump(resolvedObject) | ||
|
||
|
||
--print('resolvedObject') | ||
--require('pl.pretty').dump(objectType) | ||
|
||
local res = completeValue(fieldType.kind, resolvedObject, subSelections, context) | ||
--print('complete value result from 256 in execute.lua') | ||
--require('pl.pretty').dump(res) | ||
|
||
return completeValue(fieldType.kind, resolvedObject, subSelections, context) | ||
return res | ||
end | ||
|
||
evaluateSelections = function(objectType, object, selections, context) | ||
local groupedFieldSet = collectFields(objectType, selections, {}, {}, context) | ||
|
||
--print('print from 298, groupedFieldSet') | ||
--require('pl.pretty').dump(groupedFieldSet) | ||
--print('OBJECT') | ||
--require('pl.pretty').dump(object) | ||
--print('OBJECT TYPE') | ||
--require('pl.pretty').dump(objectType) | ||
--print('SELECTIONS') | ||
--require('pl.pretty').dump(selections) | ||
|
||
|
||
|
||
|
||
return util.map(groupedFieldSet, function(fields) | ||
return getFieldEntry(objectType, object, fields, context) | ||
end) | ||
end | ||
|
||
return function(schema, tree, rootValue, variables, operationName) | ||
|
||
|
||
local context = buildContext(schema, tree, rootValue, variables, operationName) | ||
local rootType = schema[context.operation.operation] | ||
|
||
|
||
|
||
if not rootType then | ||
error('Unsupported operation "' .. context.operation.operation .. '"') | ||
end | ||
|
||
|
||
|
||
return evaluateSelections(rootType, rootValue, context.operation.selectionSet.selections, context) | ||
end |
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.
different arbitrary types → different types as defined in the schema; what do you think?
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.
Your variant is more specific.