Skip to content

Commit

Permalink
fix: provide compatibility with @elastic/elasticsearch.js
Browse files Browse the repository at this point in the history
* Update search.ts 

Provides compatibility with @elastic/elasticsearch.js

* style: fix eslint/prettier warnings

Co-authored-by: nodkz <[email protected]>
  • Loading branch information
andreadistefano and nodkz authored Oct 6, 2021
1 parent 399ca3e commit 77f0492
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/resolvers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,19 @@ export default function createSearchResolver<TSource, TContext>(
}

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;
},
})
Expand Down

0 comments on commit 77f0492

Please sign in to comment.