From c79ca592c946f3366196b96018774b923285a4b4 Mon Sep 17 00:00:00 2001 From: Andrea Di Stefano Date: Wed, 6 Oct 2021 16:23:24 +0200 Subject: [PATCH 1/2] Update search.ts Provides compatibility with @elastic/elasticsearch.js --- src/resolvers/search.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/resolvers/search.ts b/src/resolvers/search.ts index 7e2090b..ed845eb 100644 --- a/src/resolvers/search.ts +++ b/src/resolvers/search.ts @@ -175,12 +175,18 @@ export default function createSearchResolver( } const res: any = await searchFC.resolve(rp.source, args, rp.context, rp.info); - - res.count = - typeof res.hits.total?.value === 'number' ? res.hits.total.value : res.hits.total; - res.max_score = res.hits.max_score; - res.hits = res.hits.hits; - + if (typeof res.hits === "undefined") { + res.count = + typeof res.body.hits.total?.value === 'number' ? res.body.hits.total.value : res.body.hits.total; + res.max_score = res.body.hits.max_score; + res.hits = res.body.hits.hits; + } + else { + res.count = + typeof res.hits.total?.value === 'number' ? res.hits.total.value : res.hits.total; + res.max_score = res.hits.max_score; + res.hits = res.hits.hits; + } return res; }, }) From 0888f7da18638e510db4614795170ff42422a48d Mon Sep 17 00:00:00 2001 From: nodkz Date: Wed, 6 Oct 2021 23:16:38 +0600 Subject: [PATCH 2/2] style: fix eslint/prettier warnings --- src/resolvers/search.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/resolvers/search.ts b/src/resolvers/search.ts index ed845eb..3fc94ae 100644 --- a/src/resolvers/search.ts +++ b/src/resolvers/search.ts @@ -175,13 +175,14 @@ export default function createSearchResolver( } const res: any = await searchFC.resolve(rp.source, args, rp.context, rp.info); - if (typeof res.hits === "undefined") { + if (typeof res.hits === 'undefined') { res.count = - typeof res.body.hits.total?.value === 'number' ? res.body.hits.total.value : res.body.hits.total; + typeof res.body.hits.total?.value === 'number' + ? res.body.hits.total.value + : res.body.hits.total; res.max_score = res.body.hits.max_score; res.hits = res.body.hits.hits; - } - else { + } else { res.count = typeof res.hits.total?.value === 'number' ? res.hits.total.value : res.hits.total; res.max_score = res.hits.max_score;