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

Commit b8aef01

Browse files
committed
Merge branch 'MTH-250' into feature/searchQuery-graphQl-Update-1
2 parents 8882f8c + 2e6aee7 commit b8aef01

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

doc/2. graphQl support.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Introduction
2+
3+
Vue storefront now supports using graphQl as an alternative API endpoint to get data for products, categories, products, and taxerules.
4+
For now Graphql uses resolver what fetch data from Elasticsearch. But potentialy can have different resolvers working with different Search Engines / 3rd Party APIs
5+
6+
## GraphQl Schema
7+
8+
Graphql request to this API have to match query schema defined
9+
For product it is
10+
11+
```graphql
12+
type Query {
13+
products (
14+
search: String @doc(description: "Performs a full-text search using the specified key words."),
15+
filter: ProductFilterInput @doc(description: "Identifies which product attributes to search for and return."),
16+
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
17+
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."),
18+
sort: ProductSortInput @doc(description: "Specifies which attribute to sort on, and whether to return the results in ascending or descending order.")
19+
): Products
20+
}
21+
```
22+
23+
which has result of type Products
24+
25+
```graphql
26+
27+
type Products @doc(description: "The Products object is the top-level object returned in a product search") {
28+
items: JSON @doc(description: "An array of products that match the specified search criteria")
29+
page_info: SearchResultPageInfo @doc(description: "An object that includes the page_info and currentPage values specified in the query")
30+
total_count: Int @doc(description: "The number of products returned")
31+
aggregations: JSON @doc(description: "Layered navigation filters array as aggregations")
32+
sort_fields: SortFields @doc(description: "An object that includes the default sort field and all available sort fields")
33+
}
34+
```
35+
36+
and uses defined resolver
37+
```js
38+
const resolver = {
39+
Query: {
40+
products: (_, { search, filter, sort, currentPage, pageSize }, context, rootValue) =>
41+
list(filter, sort, currentPage, pageSize, search, context, rootValue)
42+
}
43+
};
44+
```
45+
46+
For other entity types you can check schemas and resolvers in the /src/graphql/elasticsearch correspond subfolder
47+
48+
49+
## Example request
50+
51+
Below is an example request for product
52+
53+
```graphql
54+
{
55+
products(search: "bag", filter: {
56+
status: {
57+
in: [0, 1], scope: "default"
58+
},
59+
stock: {
60+
is_in_stock: {eq: true, scope: "default"}
61+
},
62+
visibility: {
63+
in: [3, 4], scope: "default"}
64+
},
65+
sort: {
66+
updated_at: DESC
67+
}
68+
) {
69+
items
70+
total_count
71+
aggregations
72+
sort_fields {
73+
options {
74+
value
75+
}
76+
}
77+
page_info {
78+
page_size
79+
current_page
80+
}
81+
}
82+
}
83+
84+
85+
```
86+
87+
To see all available product filter options please check ProductFilterInput type in the graphQl product schema
88+
89+

src/graphql/elasticsearch/catalog/resolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function list(filter, sort, currentPage, pageSize, search, context, rootVa
2525
const parseURL = context.req.url.replace(/^\/+|\/+$/g, '');
2626
let urlParts = parseURL.split('/');
2727
let esIndex = config.elasticsearch.indices[0]
28-
if (urlParts.length >= 1 && urlParts[0] != '') {
28+
if (urlParts.length >= 1 && urlParts[0] != '' && urlParts[0] != '?') {
2929
esIndex = config.storeViews[urlParts[0]].elasticsearch.index
3030
}
3131

0 commit comments

Comments
 (0)