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

Commit 664b6fe

Browse files
authored
Merge pull request #350 from ResuBaka/fix/graphql-resolvers-and-schemas
Fix/graphql resolvers and schemas
2 parents 0b82cbe + bd4ee8b commit 664b6fe

File tree

12 files changed

+101
-36
lines changed

12 files changed

+101
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.11.0-rc.2] - unreleased
8+
9+
### Fixed
10+
11+
- Fixed some smaller issues with graphql so that it is now working again with the fronted - #350
12+
13+
714
## [1.11.0-rc.1] - 2019.10.03
815

916
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"config": "^1.30.0",
5757
"cors": "^2.8.4",
5858
"elasticdump": "^3.3.12",
59-
"elasticsearch": "^15.2.0",
59+
"@elastic/elasticsearch": "5.6.*",
6060
"email-check": "^1.1.0",
6161
"express": "^4.16.3",
6262
"fs-extra": "^8.1.0",

src/graphql/elasticsearch/attribute/resolver.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import client from '../client';
33
import { buildQuery } from '../queryBuilder';
44
import { getIndexName } from '../mapping'
55

6-
async function listAttributes (attributes, context, rootValue, _sourceInclude) {
6+
async function listAttributes (attributes, context, rootValue, _source_include) {
77
let query = buildQuery({ filter: attributes, pageSize: 150, type: 'attribute' });
88

9-
if (_sourceInclude === undefined) {
10-
_sourceInclude = config.entities.attribute.includeFields
9+
if (!_source_include) {
10+
_source_include = config.entities.attribute.includeFields
1111
}
1212

1313
const response = await client.search({
1414
index: getIndexName(context.req.url),
1515
type: config.elasticsearch.indexTypes[3],
1616
body: query,
17-
_sourceInclude
17+
_source_include
1818
});
1919

20-
return response;
20+
return response.body;
2121
}
2222

2323
const resolver = {

src/graphql/elasticsearch/catalog/resolver.js

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

14-
async function list (filter, sort, currentPage, pageSize, search, context, rootValue, _sourceInclude, _sourceExclude) {
14+
async function list (filter, sort, currentPage, pageSize, search, context, rootValue, _source_include, _source_exclude) {
1515
let _req = {
1616
query: {
17-
_source_exclude: _sourceExclude,
18-
_source_include: _sourceInclude
17+
_source_exclude,
18+
_source_include
1919
}
2020
}
2121

@@ -34,26 +34,28 @@ async function list (filter, sort, currentPage, pageSize, search, context, rootV
3434
index: esIndex,
3535
type: config.elasticsearch.indexTypes[0],
3636
body: query,
37-
_sourceInclude,
38-
_sourceExclude
37+
_source_include,
38+
_source_exclude
3939
});
4040

41-
if (esResponse && esResponse.hits && esResponse.hits.hits) {
41+
const { body } = esResponse
42+
43+
if (body && body.hits && body.hits.hits) {
4244
// process response result (caluclate taxes etc...)
43-
esResponse.hits.hits = await esResultsProcessor(esResponse, _req, config.elasticsearch.indexTypes[0], esIndex);
45+
body.hits.hits = await esResultsProcessor(body, _req, config.elasticsearch.indexTypes[0], esIndex);
4446
}
4547

4648
let response = {}
4749

4850
// Process hits
4951
response.items = []
50-
esResponse.hits.hits.forEach(hit => {
52+
body.hits.hits.forEach(hit => {
5153
let item = hit._source
5254
item._score = hit._score
5355
response.items.push(item)
5456
});
5557

56-
response.total_count = esResponse.hits.total
58+
response.total_count = body.hits.total
5759

5860
// Process sort
5961
let sortOptions = []
@@ -66,7 +68,7 @@ async function list (filter, sort, currentPage, pageSize, search, context, rootV
6668
)
6769
}
6870

69-
response.aggregations = esResponse.aggregations
71+
response.aggregations = body.aggregations
7072
response.sort_fields = {}
7173
if (sortOptions.length > 0) {
7274
response.sort_fields.options = sortOptions

src/graphql/elasticsearch/catalog/schema.graphqls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ input FilterTypeInput @doc(description: "FilterTypeInput specifies which action
4141
gte: String @doc(description: "Greater than or equal to")
4242
gteq: String @doc(description: "Greater than or equal to")
4343
in: [JSON] @doc(description: "In. The value can contain a set of comma-separated values")
44-
like: String @doc(description: "Like. The specified value can contain % (percent signs) to allow matching of 0 or more characters")
44+
like: [String] @doc(description: "Like. The specified value can contain % (percent signs) to allow matching of 0 or more characters")
4545
lt: String @doc(description: "Less than")
4646
lte: String @doc(description: "Less than or equal to")
4747
lteq: String @doc(description: "Less than or equal to")
@@ -151,6 +151,7 @@ input ProductFilterInput @doc(description: "ProductFilterInput defines the filte
151151
stock: ProductFilterInput @doc(description: "The product stock. Customers use this stock to identify the product.")
152152
is_in_stock: FilterTypeInput @doc(description: "Is product in stock")
153153
keyword: FilterTypeInput @doc(description: "keyword filter input")
154+
url_path: FilterTypeInput @doc(description: "The url path assigned to the product")
154155
}
155156

156157
type LayerFilter {
@@ -182,4 +183,4 @@ type SortFields @doc(description: "SortFields contains a default value for sort
182183
enum SortEnum {
183184
ASC
184185
DESC
185-
}
186+
}

src/graphql/elasticsearch/category/resolver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import client from '../client';
33
import { buildQuery } from '../queryBuilder';
44
import { getIndexName } from '../mapping'
55

6-
async function list (search, filter, currentPage, pageSize = 200, sort, context, rootValue, _sourceInclude) {
6+
async function list (search, filter, currentPage, pageSize = 200, sort, context, rootValue, _source_include) {
77
let query = buildQuery({ search, filter, currentPage, pageSize, sort, type: 'category' });
88

9-
if (_sourceInclude === undefined) {
10-
_sourceInclude = config.entities.category.includeFields
9+
if (!_source_include) {
10+
_source_include = config.entities.category.includeFields
1111
}
1212

1313
const response = await client.search({
1414
index: getIndexName(context.req.url),
1515
type: config.elasticsearch.indexTypes[1],
1616
body: query,
17-
_sourceInclude
17+
_source_include
1818
});
1919

2020
return response;

src/graphql/elasticsearch/category/schema.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ input CategorySortInput {
5959
display_mode: SortEnum @doc(description: "Category display mode")
6060
is_anchor: SortEnum @doc(description: "Is filter avalaible in category")
6161
page_layout: SortEnum @doc(description: "Category page layout")
62-
}
62+
_score: SortEnum @doc(description: "Category page layout")
63+
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import config from 'config';
2-
import elasticsearch from 'elasticsearch';
2+
import elasticsearch from '@elastic/elasticsearch';
33

44
const client = new elasticsearch.Client({
5-
host: {
6-
host: config.elasticsearch.host,
7-
port: config.elasticsearch.port,
8-
protocol: config.elasticsearch.protocol
9-
}
5+
node: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`
106
});
117

128
export default client;

src/graphql/elasticsearch/cms/resolver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import config from 'config';
22
import client from '../client';
33
import { buildQuery } from '../queryBuilder';
44

5-
async function list (filter, currentPage, pageSize = 200, _sourceInclude, type) {
6-
let query = buildQuery({ filter, currentPage, pageSize, _sourceInclude, type });
5+
async function list (filter, currentPage, pageSize = 200, _source_include, type) {
6+
let query = buildQuery({ filter, currentPage, pageSize, _source_include, type });
77

88
const response = await client.search({
99
index: config.elasticsearch.indices[0],
1010
body: query,
1111
type,
12-
_sourceInclude
12+
_source_include
1313
});
14-
const items = buildItems(response)
14+
const items = buildItems(response.body)
1515

1616
return items;
1717
}

src/graphql/elasticsearch/cms/schema.graphqls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ input CmsInput @doc(description: "ProductFilterInput defines the filters to be u
1717
id: FilterTypeInput @doc(description: "Id of the CMS entity")
1818
identifier: FilterTypeInput @doc(description: "Identifiers of the CMS entity")
1919
store_id: FilterTypeInput @doc(description: "Store Id of the CMS entity")
20+
url_path: FilterTypeInput @doc(description: "The url path assigned to the cms_page")
2021
}
2122

2223
type CmsPage @doc(description: "CMS pages information") {
@@ -32,6 +33,7 @@ type CmsPages @doc(description: "CMS page defines all CMS page information") {
3233
meta_description: String @doc(description: "CMS page meta description")
3334
meta_keywords: String @doc(description: "CMS page meta keywords")
3435
store_id: Int @doc(description: "Store Id of CMS page")
36+
url_path: String @doc(description: "CMS page meta keywords")
3537
}
3638

3739
type CmsBlocks @doc(description: "CMS blocks information") {
@@ -40,6 +42,7 @@ type CmsBlocks @doc(description: "CMS blocks information") {
4042

4143
type CmsBlock @doc(description: "CMS block defines all CMS block information") {
4244
identifier: String @doc(description: "CMS block identifier")
45+
id: Int @doc(description: "CMS block identifier")
4346
title: String @doc(description: "CMS block title")
4447
content: String @doc(description: "CMS block content")
4548
creation_time: String @doc(description: "Timestamp indicating when the CMS block was created")
@@ -60,4 +63,4 @@ type CmsHierarchy {
6063
request_url: String @doc(description: "Request URL of CMS hierarchy node")
6164
xpath: String @doc(description: "XPATH of CMS hierarchy node")
6265
store_id: Int @doc(description: "Store Id of CMS hierarchy node")
63-
}
66+
}

0 commit comments

Comments
 (0)