fix(graphql): n+1 on single dossier loading

This commit is contained in:
Paul Chavard 2023-01-17 11:23:21 +01:00
parent 9db84cfd25
commit b5c189de63

View file

@ -38,11 +38,12 @@ module Types
end
def dossier(number:)
if context.internal_use?
dossier = if context.internal_use?
Dossier.state_not_brouillon.for_api_v2.find(number)
else
Dossier.visible_by_administration.for_api_v2.find(number)
end
DossierPreloader.load_one(dossier)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end