fix(graphql): return empty arrays from loaders when loading collections

This commit is contained in:
Paul Chavard 2023-04-18 09:31:17 +02:00
parent 110a8aec97
commit 2a09f1d505
3 changed files with 34 additions and 2 deletions

View file

@ -13,7 +13,7 @@ module Loaders
def perform(keys)
query(keys).each { |record| fulfill(record.stable_id, [record].compact) }
keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
keys.each { |key| fulfill(key, []) unless fulfilled?(key) }
end
private

View file

@ -21,7 +21,7 @@ module Loaders
fulfilled_value = @array ? [record].compact : record
fulfill(record.public_send(@column), fulfilled_value)
end
keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
keys.each { |key| fulfill(key, @array ? [] : nil) unless fulfilled?(key) }
end
private