Merge pull request #8439 from tchak/fix-graphql-dossier-n+1

fix(graphql): n+1 on single dossier loading
This commit is contained in:
Paul Chavard 2023-01-17 11:43:23 +01:00 committed by GitHub
commit ca4f597c13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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