Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 81b3b07

Browse files
authored
Merge pull request #286 from yuriboyko/feature/searchQuery-graphQl-Update-1
Fix productProcessor emtpy request with using graphql
2 parents 00387cb + 2a9f829 commit 81b3b07

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/graphql/elasticsearch/catalog/processor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import config from 'config'
22
import ProcessorFactory from '../../../processor/factory'
33

4-
export default function esResultsProcessor (response, entityType, indexName, req, res) {
4+
export default function esResultsProcessor (response, esRequest, entityType, indexName) {
55
return new Promise((resolve, reject) => {
66
const factory = new ProcessorFactory(config)
7-
let resultProcessor = factory.getAdapter(entityType, indexName, req, res)
7+
let resultProcessor = factory.getAdapter(entityType, indexName, esRequest, response)
88

99
if (!resultProcessor) {
10-
resultProcessor = factory.getAdapter('default', indexName, req, res) // get the default processor
10+
resultProcessor = factory.getAdapter('default', indexName, esRequest, response) // get the default processor
1111
}
1212

1313
resultProcessor.process(response.hits.hits)

src/graphql/elasticsearch/catalog/resolver.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ const resolver = {
1212
};
1313

1414
async function list (filter, sort, currentPage, pageSize, search, context, rootValue, _sourceInclude, _sourceExclude) {
15-
const { req, res } = context;
15+
let _req = {
16+
query: {
17+
_source_exclude: _sourceExclude,
18+
_source_include: _sourceInclude
19+
}
20+
}
1621

1722
let query = buildQuery({
1823
filter: filter,
@@ -23,7 +28,7 @@ async function list (filter, sort, currentPage, pageSize, search, context, rootV
2328
type: 'product'
2429
});
2530

26-
let esIndex = getIndexName(req.url)
31+
let esIndex = getIndexName(context.req.url)
2732

2833
let esResponse = await client.search({
2934
index: esIndex,
@@ -35,7 +40,7 @@ async function list (filter, sort, currentPage, pageSize, search, context, rootV
3540

3641
if (esResponse && esResponse.hits && esResponse.hits.hits) {
3742
// process response result (caluclate taxes etc...)
38-
esResponse.hits.hits = await esResultsProcessor(esResponse, config.elasticsearch.indexTypes[0], esIndex, req, res);
43+
esResponse.hits.hits = await esResultsProcessor(esResponse, _req, config.elasticsearch.indexTypes[0], esIndex);
3944
}
4045

4146
let response = {}

0 commit comments

Comments
 (0)