Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVDOCS-5007: [update] add redirect feature #798

Merged
merged 22 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/storefront/graphql/examples/products.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ Query all products by not including an argument for `products`.

You can also query for featured products, related products, and more. See the [GraphQL Storefront Playground](https://developer.bigcommerce.com/graphql-storefront/playground) for full schema documentation.

### Get a product by URL using a route node

Query a list of products by matching the `Redirect` type.

```graphql filename="Get a product with the redirect type" showLineNumbers copy

query {
site {
route(path: "/laura-ashley-duck-egg-paint/113699-master/", redirect: [FOLLOW|IGNORE] = IGNORE) {
redirect # <--- new redirect node of a type Redirect
node {
id
... on Product {
name
}
}
}
}
}
```

## Get product identifiers

Query basic information for products. The following query retrieves both product identifiers and basic information for the specified product:
Expand Down
66 changes: 66 additions & 0 deletions docs/storefront/headless/routes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Routes with the GraphQL Storefront API

BigCommerce's GraphQL Storefront API lets you retrieve routes from each storefront channel. By accessing routes and product URLs, you can easily build headless storefront applications using BigCommerce's built-in content.

The `LookUpUrl` capability supports redirects, helping you determine which pages to display. The `Redirect` node within the `route` node will return redirect details if they exist for a given path. If no redirect is configured, it will return `null`.

The `route` node includes a redirect argument with a default value of `IGNORE`. This makes the `route` node backward-compatible with previous API versions.

## Redirect enum values

The redirect argument supports the following values:

* **IGNORE**: The Storefront GraphQL API ignores redirects and uses custom URLs. If both a redirect and an entity URL are configured for the same path, both the `redirect` and `node` nodes will return non-null values for their respective URLs.

* **FOLLOW**:

* For dynamic or association redirects, the `node` node will return the entity (e.g., category, product) to which the redirect points.
* For static/manual redirects, the `node` node will return null (since there’s no associated entity), but the `redirect` node will still return the redirect details.

## Example query

Here is an example query for retrieving a product with the redirect type:

```graphql filename="Get a product with the redirect type" showLineNumbers copy

query LookUpUrl(
$urlPath: String!
# Use GraphQL Query Variables to provide a path
) {
site {
route(path: $urlPath) {
node {
__typename
id
# A different response is returned based on which type of object was matched
... on Category {
name
description
}
... on Brand {
name
defaultImage {
url(width: 200)
}
}
... on Product {
name
description
images {
edges {
node {
url(width: 500, height: 500)
}
}
}
}
... on Redirect {
# all redirect attributes
toUrl
}
}
}
}
}
```