|
| 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 | + |
0 commit comments