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

Support filters over 1:N connections #210

Merged
merged 2 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions graphql/accessor_general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -902,20 +902,22 @@ local function process_tuple(self, state, tuple, opts)
end

-- make subrequests if needed
local truncated_filter = table.copy(filter)
for k, v in pairs(filter) do
if obj[k] == nil then
local field_name = k
local sub_filter = v
local field = resolveField(field_name, obj, sub_filter)
local field, is_list = resolveField(field_name, obj, sub_filter)
if field == nil then return true end
obj[k] = field
-- XXX: Remove the value from a filter? But then we need to copy
-- the filter each time in the case.
if is_list then
if next(field) == nil then return true end
end
truncated_filter[k] = nil
end
end

-- filter out non-matching objects
local match = utils.is_subtable(obj, filter) and
local match = utils.is_subtable(obj, truncated_filter) and
match_using_re(obj, pcre)
if do_filter then
if not match then return true end
Expand Down Expand Up @@ -1570,7 +1572,7 @@ end
--- - `qcontext` (table) can be used by an accessor to store any
--- query-related data;
--- - `resolveField(field_name, object, filter, opts)` (function) for
--- performing a subrequest on a fields connected using a 1:1 connection.
--- performing a subrequest on a fields connected using a connection.
--- - extra_args
--- - exp_tuple_count
function accessor_general.new(opts, funcs)
Expand Down
9 changes: 7 additions & 2 deletions graphql/convert_schema/resolve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ function resolve.gen_resolve_function(collection_name, connection,
c.destination_collection))
local opts = table.copy(opts or {})
opts.is_hidden = true
return bare_destination_type.fields[field_name].resolve(
object, filter, info, opts)
local result, field_type =
bare_destination_type.fields[field_name].resolve(object,
filter, info, opts)
local field_type = field_type or
bare_destination_type.fields[field_name].kind
local is_list = core_types.nullable(field_type).__type == 'List'
return result, is_list
end
end

Expand Down
8 changes: 4 additions & 4 deletions graphql/convert_schema/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ local function for_each_connection(state, connection_types, func)
end
end

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

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

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

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

Expand Down
Loading