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

Commit dae00e3

Browse files
authored
Merge pull request #210 from tarantool/gh-94-filter-over-1-n-conn
Support filters over 1:N connections
2 parents 2ce2d88 + b73c79b commit dae00e3

File tree

6 files changed

+763
-569
lines changed

6 files changed

+763
-569
lines changed

graphql/accessor_general.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,22 @@ local function process_tuple(self, state, tuple, opts)
902902
end
903903

904904
-- make subrequests if needed
905+
local truncated_filter = table.copy(filter)
905906
for k, v in pairs(filter) do
906907
if obj[k] == nil then
907908
local field_name = k
908909
local sub_filter = v
909-
local field = resolveField(field_name, obj, sub_filter)
910+
local field, is_list = resolveField(field_name, obj, sub_filter)
910911
if field == nil then return true end
911-
obj[k] = field
912-
-- XXX: Remove the value from a filter? But then we need to copy
913-
-- the filter each time in the case.
912+
if is_list then
913+
if next(field) == nil then return true end
914+
end
915+
truncated_filter[k] = nil
914916
end
915917
end
916918

917919
-- filter out non-matching objects
918-
local match = utils.is_subtable(obj, filter) and
920+
local match = utils.is_subtable(obj, truncated_filter) and
919921
match_using_re(obj, pcre)
920922
if do_filter then
921923
if not match then return true end
@@ -1570,7 +1572,7 @@ end
15701572
--- - `qcontext` (table) can be used by an accessor to store any
15711573
--- query-related data;
15721574
--- - `resolveField(field_name, object, filter, opts)` (function) for
1573-
--- performing a subrequest on a fields connected using a 1:1 connection.
1575+
--- performing a subrequest on a fields connected using a connection.
15741576
--- - extra_args
15751577
--- - exp_tuple_count
15761578
function accessor_general.new(opts, funcs)

graphql/convert_schema/resolve.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ function resolve.gen_resolve_function(collection_name, connection,
123123
c.destination_collection))
124124
local opts = table.copy(opts or {})
125125
opts.is_hidden = true
126-
return bare_destination_type.fields[field_name].resolve(
127-
object, filter, info, opts)
126+
local result, field_type =
127+
bare_destination_type.fields[field_name].resolve(object,
128+
filter, info, opts)
129+
local field_type = field_type or
130+
bare_destination_type.fields[field_name].kind
131+
local is_list = core_types.nullable(field_type).__type == 'List'
132+
return result, is_list
128133
end
129134
end
130135

graphql/convert_schema/schema.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ local function for_each_connection(state, connection_types, func)
161161
end
162162
end
163163

164-
--- Add arguments corresponding to 1:1 connections (nested filters).
164+
--- Add arguments corresponding to connections (nested filters).
165165
---
166166
--- @tparam table state graphql_tarantool instance
167167
local function add_connection_arguments(state)
@@ -170,8 +170,8 @@ local function add_connection_arguments(state)
170170
-- map source collection and connection name to an input object
171171
local lookup_input_objects = {}
172172

173-
-- create InputObjects for each 1:1 connection of each collection
174-
for_each_connection(state, {'1:1'}, function(collection_name, c)
173+
-- create InputObjects for each connection of each collection
174+
for_each_connection(state, {'1:1', '1:N'}, function(collection_name, c)
175175
-- XXX: support multihead connections
176176
if c.variants ~= nil then return end
177177

@@ -196,7 +196,7 @@ local function add_connection_arguments(state)
196196

197197
-- update fields of collection arguments and input objects with other input
198198
-- objects
199-
for_each_connection(state, {'1:1'}, function(collection_name, c)
199+
for_each_connection(state, {'1:1', '1:N'}, function(collection_name, c)
200200
-- XXX: support multihead connections
201201
if c.variants ~= nil then return end
202202

0 commit comments

Comments
 (0)