This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
DEVDOCS-5007: [new] GQL Storefront, Extended GQL LookupURL Route Redirects #2111
Closed
bc-tgomez
wants to merge
12
commits into
main
from
DEVDOCS-5007-Extend-LookUpUrl-capability-in-Storefront-GraphQL-API-to-account-for-redirects
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d4dcd05
Set up page file
bc-tgomez 2622e27
Set up template
bc-tgomez 8bdffb2
Push update
bc-tgomez 8cc3802
Add redirect product request and response
bc-tgomez 9b16eca
Add more queries
bc-tgomez b2c15d2
Add category, brand, and page redirects examples
bc-tgomez 682dd05
Revise Routes URL
bc-tgomez 039cee8
Add manual URL redirect and more edits
bc-tgomez b6288aa
Merge branch 'main' into DEVDOCS-5007-Extend-LookUpUrl-capability-in-…
bc-tgomez db89821
Make edits to the example descriptions.
bc-tgomez cfd9732
Add Resource links to doc
bc-tgomez fb8cf6a
Made more edits to the descriptions.
bc-tgomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,368 @@ | ||
**GraphQL Storefront API** | ||
# Guide to Working with Redirects | ||
|
||
BigCommerce's GraphQL Storefront API lets frontend developers modify [Redirects](/docs/rest-content/store-content/redirects##upsert-redirects) from a store. These built-in capabilities also allow developers to customize their hosted or headless storefronts with Redirects. | ||
|
||
<Callout type="information"> | ||
#### Create a Redirect API | ||
The [Create a Redirect](/docs/rest-content/store-content/redirects#create-a-redirect) API endpoint is deprecated. Use the [Upsert Redirects](/docs/rest-management/redirects) API endpoint instead to update new redirect data. | ||
</Callout> | ||
|
||
The GraphQL Storefront API lets you set the following redirect attributes and more: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- Redirect site traffic to a manual URL on the domain | ||
- Set redirections for GQL types such as: Product, Page, Brand, Blog Post, and Category | ||
- Use redirect behavior to enable an optional `FOLLOW` or `IGNORE` argument in the `route`s `path` | ||
|
||
## Prerequisites | ||
|
||
To complete the guide you will need the following: | ||
- A BigCommerce Store with Multi-Storefront enabled | ||
- A [Storefront API](/docs/rest-authentication/tokens#create-a-token) token | ||
- A 301 redirect set | ||
- An understanding of [Routes](/docs/storefront/headless/site-content#routes) | ||
|
||
For more information on formatting the request payload, see the query example section of the [GraphQL Storefront API Overview](/docs/storefront/graphql#querying-within-a-bigcommerce-storefront). | ||
|
||
## Redirect to a product | ||
|
||
Divert traffic from an old URL to a new URL accross all storefronts. Set the `path` with the product's URL to redirect traffic from an old product URL, to a new product URL. In this example, the old URL is set to redirect product to a new product URL in the query. The response confirms that traffic is diverting from the old product URL, to the new product URL. | ||
|
||
<Callout type="information"> | ||
#### Optional Redirect Node Arguments | ||
If you add optional arguments on the `route` node, check that the correct `redirectBehavior` is in use. For instance, when using the default `IGNORE` to set a manual URL redirect >>>still testing behavior>>> | ||
</Callout> | ||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a Product" showLineNumbers copy | ||
query { | ||
site { | ||
route(path: "/chambray-towel-1/", redirectBehavior: FOLLOW) { | ||
node { | ||
... on Product { | ||
name | ||
entityId | ||
} | ||
} | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a Product" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"node": { | ||
"name": "Test Product", | ||
"entityId": 127 | ||
}, | ||
"redirect": { | ||
"to": { | ||
"__typename": "ProductRedirect" | ||
}, | ||
"toUrl": "https://www.test-store.com/test-product/", | ||
"fromPath": "/chambray-towel-1/" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=ProductRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
## Redirect to a page | ||
|
||
Run this query across your storefront data to redirect to a new page. | ||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a Page" showLineNumbers copy | ||
query { | ||
site { | ||
route(path: "/home-and-kitchen/", redirectBehavior: FOLLOW) { | ||
node { | ||
... on Page{ | ||
name | ||
entityId | ||
} | ||
} | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a Page" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"node": { | ||
"name": "Towel Collection", | ||
"entityId": 6 | ||
}, | ||
"redirect": { | ||
"to": { | ||
"__typename": "PageRedirect" | ||
}, | ||
"toUrl": "https://www.test-store.com/chambray-towel/", | ||
"fromPath": "/home-and-kitchen/" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=PageRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
|
||
## Site redirect to a blog post | ||
|
||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a Blog Post" showLineNumbers copy | ||
query { | ||
site { | ||
route(path: "/your-first-blog-post/", redirectBehavior: FOLLOW) { | ||
node { | ||
... on BlogPost{ | ||
name | ||
entityId | ||
} | ||
} | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a Blog Post" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"node": { | ||
"name": "2023 Events Calendar", | ||
"entityId": 3 | ||
}, | ||
"redirect": { | ||
"to": { | ||
"__typename": "BlogPostRedirect" | ||
}, | ||
"toUrl": "https://www.test-store.com/blog/2024-events-calendar/", | ||
"fromPath": "/your-first-blog-post/" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=BlogPostRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
|
||
## Redirect to a category | ||
|
||
In this example, a site redirect query is redirecting traffic from an old category URL, to a new category URL. | ||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a Category" showLineNumbers copy | ||
{ | ||
site { | ||
route(path: "/home-office/", redirectBehavior: FOLLOW) { | ||
node { | ||
... on Category { | ||
name | ||
entityId | ||
} | ||
} | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a Category" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"node": { | ||
"name": "Home Office", | ||
"entityId": 29 | ||
}, | ||
"redirect": { | ||
"to": { | ||
"__typename": "CategoryRedirect" | ||
}, | ||
"toUrl": "https://www.test-store.com/housewares/", | ||
"fromPath": "/home-office/" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=CategoryRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
## Redirect to a brand | ||
|
||
Create a site redirect to divert traffic from an old URL to a new URL. In this example, a site redirect query is redirecting traffic from an old brand URL, to a new brand URL. | ||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a Brand" showLineNumbers copy | ||
{ | ||
site { | ||
route(path: "/hand-made-joy/", redirectBehavior: FOLLOW) { | ||
node { | ||
... on Brand { | ||
name | ||
entityId | ||
} | ||
} | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a Brand" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"node": { | ||
"name": "Hand Made Joy", | ||
"entityId": 38 | ||
}, | ||
"redirect": "https://www.test-store.com/brands/hand-made-joy/" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=BrandRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
## Manual URL redirect | ||
|
||
Run this query and divert traffic from an old page URL, to a new page URL. | ||
|
||
<tabs items={['Request', 'Response']}> | ||
<tab> | ||
``` graphql filename="Example query request: Redirect to a manual input URL" showLineNumbers copy | ||
{ | ||
site { | ||
route(path: "/contact-us/", redirectBehavior: FOLLOW) { | ||
redirect { | ||
to { | ||
__typename | ||
} | ||
toUrl | ||
fromPath | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
<tab> | ||
``` graphql filename="Example query response: Redirect to a manual input URL" showLineNumbers copy | ||
{ | ||
"data": { | ||
"site": { | ||
"route": { | ||
"redirect": { | ||
"to": { | ||
"__typename": "PageRedirect" | ||
}, | ||
"toUrl": "https://www.test-store.com/contact-us/", | ||
"fromPath": "/lets-chat/" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</tab> | ||
</tabs> | ||
|
||
|
||
<a href="https://developer.bigcommerce.com/graphql?playground_tab=ManualRedirect" target="_blank">**Try it in GraphQL Playground**</a> | ||
|
||
### FAQs | ||
|
||
**Query is returning `null` values** | ||
|
||
The `redirect` node query returns a `null` value when details for a given path are missing. Check that the 301 redirect contains all the required details. Add any missing details and run the query again. For more information about 301 redirects see [301 Redirects](https://support.bigcommerce.com/s/article/MSF-301-Redirects?language=en_US). | ||
|
||
## Resources | ||
### GraphQL documentation | ||
[GraphQL Storefront API Overview](/docs/storefront/graphql#querying-within-a-bigcommerce-storefront) | ||
[Routes](/docs/storefront/headless/site-content#routes) | ||
|
||
### REST API reference | ||
[Storefront API](/docs/rest-authentication/tokens#create-a-token) | ||
[Upsert Redirects](/docs/rest-management/redirects) | ||
[Redirects](/docs/rest-content/store-content/redirects#create-a-redirect) | ||
|
||
### Support articles | ||
[301 Redirects](https://support.bigcommerce.com/s/article/MSF-301-Redirects?language=en_US) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
GraphQL Storefront API
does not allow modification of redirects, just the standard (REST) API....v2 and v3.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or headless
I don't think redirect behavior really relates to headless stores unless I am misunderstanding your point.