From bea0e3b601bf0b597eb40c75ba22e521b3df23aa Mon Sep 17 00:00:00 2001 From: Kevin Harper Date: Sun, 3 Mar 2019 23:00:31 -0600 Subject: [PATCH 1/2] URL Rewrite updates --- _data/toc/graphql.yml | 4 +- guides/v2.3/graphql/reference/products.md | 15 +- guides/v2.3/graphql/reference/url-resolver.md | 130 ++++++++++++++++-- 3 files changed, 134 insertions(+), 15 deletions(-) diff --git a/_data/toc/graphql.yml b/_data/toc/graphql.yml index ccfe1befced..d3fb833d5ae 100644 --- a/_data/toc/graphql.yml +++ b/_data/toc/graphql.yml @@ -65,7 +65,7 @@ pages: - label: Other objects children: - - label: CMS endpoints + - label: CMS endpoint url: /graphql/reference/cms.html - label: CustomAttributeMetadata endpoint @@ -83,7 +83,7 @@ pages: - label: Store endpoint url: /graphql/reference/store-config.html - - label: urlResolver endpoint + - label: UrlRewrite endpoint url: /graphql/reference/url-resolver.html - label: Wishlist endpoint diff --git a/guides/v2.3/graphql/reference/products.md b/guides/v2.3/graphql/reference/products.md index 24c91a7b304..cfe30bde472 100644 --- a/guides/v2.3/graphql/reference/products.md +++ b/guides/v2.3/graphql/reference/products.md @@ -16,6 +16,7 @@ products( sort: ProductSortInput ): Products ``` + Each query attribute is defined below: Attribute | Description @@ -49,7 +50,7 @@ Magento processes the attribute values specified in a `ProductFilterInput` as The following attributes can be used to create filters. See the [Response](#Response) section for information about each attribute. -``` +``` text country_of_manufacture created_at custom_design @@ -87,6 +88,8 @@ thumbnail thumbnail_label tier_price updated_at +url_key +url_path weight ``` @@ -114,13 +117,13 @@ content="GraphQL automatically filters out a product attribute if ALL of the fol The system returns a `Products` object containing the following information: -{% highlight json %} +``` json items: [ProductInterface] page_info: SearchResultPageInfo total_count: Int filters: [LayerFilter] sort_fields: SortFields -{% endhighlight %} +``` Each attribute is described below: @@ -145,6 +148,7 @@ When a product requires a filter attribute that is not a field on its output sch ``` + This example adds `field_to_sort` and `other_field_to_sort` attributes to the `additionalAttributes` array defined in the `ProductEntityAttributesForAst` class. The array already contains the `min_price`, `max_price`, and `category_ids` attributes. ## ProductInterface {#ProductInterface} @@ -206,6 +210,9 @@ Attribute | Data type | Description `tier_prices` | [ProductTierPrices] | An array of [ProductTierPrices](#ProductTier) objects `type_id` | String | One of `simple`, `virtual`, `bundle`, `downloadable`,`grouped`, `configurable` `updated_at` | String | The timestamp indicating when the product was last updated +`url_key` | String | The part of the URL that identifies the product. This attribute is defined in the `CatalogUrlRewrite` module +`url_path` | String | The part of the URL that precedes the `url_key`. This attribute is defined in the `CatalogUrlRewrite` module +`url_rewrites` | [UrlRewrite] | A list of URL rewrites. See [UrlRewrite endpoint]({{ page.baseurl }}/graphql/reference/url-resolver.html#UrlRewrite) for more information and an example query `website_ids` | [Int] | An array of website IDs in which the product is available {:style="table-layout:auto;"} @@ -342,7 +349,7 @@ Field | Type | Description ### LayerFilterItemInterface -`LayerFilterItemInterface ` contains an array of items that match the terms defined in the filter. +`LayerFilterItemInterface` contains an array of items that match the terms defined in the filter. Field | Type | Description --- | --- | --- diff --git a/guides/v2.3/graphql/reference/url-resolver.md b/guides/v2.3/graphql/reference/url-resolver.md index 39296fe696d..a825bdca422 100644 --- a/guides/v2.3/graphql/reference/url-resolver.md +++ b/guides/v2.3/graphql/reference/url-resolver.md @@ -1,33 +1,60 @@ --- group: graphql -title: urlResolver endpoint +title: UrlRewrite endpoint --- -The `urlResolver` query returns the canonical URL for a specified product, category or CMS page. An external app can render a page by a url without any prior knowledge about the landing page. +A merchant can reconfigure (rewrite) the URL to any product, category, or CMS page. When the rewrite goes into effect, any links that point to the previous URL are redirected to the new address. -## Query structure +## Query -`urlResolver(url: String!): EntityUrl` +The `urlResolver` query returns the canonical URL for a specified product, category or CMS page. An external app can render a page by a URL without any prior knowledge about the landing page. -where: +### Syntax + +`{urlResolver(url: String!): EntityUrl}` + +### EntityUrl attributes + +The `EntityUrl` output object contains the `id`, `canonical_url`, and `type` attributes. Attribute | Data Type | Description --- | --- | --- -`EntityUrl` | `EntityUrl` | An output object containing the `id`, `relative_url`, and `type` attributes. +`canonical_url` | String | The internal relative URL. If the specified `url` is a redirect, the query returns the redirected URL, not the original. `id` | Int | The ID assigned to the object associated with the specified `url`. This could be a product ID, category ID, or page ID. -`relative_url` | String | The internal relative URL. If the specified `url` is a redirect, the query returns the redirected URL, not the original. `type` | UrlRewriteEntityTypeEnum | The value of `UrlRewriteEntityTypeEnum` is one of PRODUCT, CATEGORY, or CMS_PAGE. `url` | String | The URL to resolve. Magento stores product and category URLs with the `.html` extension. CMS URLs do not contain the extension. +### UrlRewrite object {#UrlRewrite} + +The `products` query can request details about the `UrlRewrite` object. + +Field | Type | Description +--- | --- | --- +`parameters` | [[`HttpQueryParameter`]](#HttpQueryParameter) | An array of target path parameters +`url` | String | The request URL +{:style="table-layout:auto;"} + +### HttpQueryParameter object {#HttpQueryParameter} + +The `HttpQueryParameter` object provides details about target path parameters. + +Field | Type | Description +--- | --- | --- +`name` | String | The parameter name, such as `id` +`value` | String | The value assigned to the parameter +{:style="table-layout:auto;"} + ## Example usage +The following query returns information about the URL containing `joust-duffle-bag.html`. + **Request** ``` text { urlResolver(url:"joust-duffle-bag.html") { id - relative_url + canonical_url type } } @@ -40,9 +67,94 @@ Attribute | Data Type | Description "data": { "urlResolver": { "id": 1, - "relative_url": "catalog/product/view/id/1", + "canonical_url": "catalog/product/view/id/1", "type": "PRODUCT" } } } ``` + +The following product query returns URL rewrite information about the Joust Duffle Bag. + +**Request** + +``` text +{ + products(search: "Joust") { + items { + name + sku + url_rewrites { + url + parameters { + name + value + } + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "products": { + "items": [ + { + "name": "Joust Duffle Bag", + "sku": "24-MB01", + "url_rewrites": [ + { + "url": "no-route", + "parameters": [ + { + "name": "page_id", + "value": "1" + } + ] + }, + { + "url": "joust-duffle-bag.html", + "parameters": [ + { + "name": "id", + "value": "1" + } + ] + }, + { + "url": "gear/joust-duffle-bag.html", + "parameters": [ + { + "name": "id", + "value": "1" + }, + { + "name": "category", + "value": "3" + } + ] + }, + { + "url": "gear/bags/joust-duffle-bag.html", + "parameters": [ + { + "name": "id", + "value": "1" + }, + { + "name": "category", + "value": "4" + } + ] + } + ] + } + ] + } + } +} +``` \ No newline at end of file From baf222f856bf81ef5dd8a01cfbbc6e443440be34 Mon Sep 17 00:00:00 2001 From: Kevin Harper Date: Sun, 3 Mar 2019 23:19:57 -0600 Subject: [PATCH 2/2] Change code gates to text --- guides/v2.3/graphql/reference/products.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/v2.3/graphql/reference/products.md b/guides/v2.3/graphql/reference/products.md index cfe30bde472..5bd466a246e 100644 --- a/guides/v2.3/graphql/reference/products.md +++ b/guides/v2.3/graphql/reference/products.md @@ -117,7 +117,7 @@ content="GraphQL automatically filters out a product attribute if ALL of the fol The system returns a `Products` object containing the following information: -``` json +``` text items: [ProductInterface] page_info: SearchResultPageInfo total_count: Int