What does FOLLOW return for a BigCommerce GraphQL route redirect?

The Citead team, updated

In short. FOLLOW returns the target entity for a dynamic redirect and redirect details with a null node for a manual redirect.

Definition: In BigCommerce's GraphQL Storefront API, redirectBehavior: FOLLOW puts the entity targeted by a dynamic redirect in the route's node field. For a manual redirect, node is null and the redirect field carries the destination details.

Key facts

  • BigCommerce requires only a URL path for a route lookup. The response can be an entity, a redirect, or nothing when the path relates to neither, according to the storefront routes documentation.
  • The route node supports store 301 redirects, represented as either manual or dynamic redirects.
  • A dynamic redirect exposes an entity type and entity ID for an existing store resource. The documented types are ProductRedirect, BrandRedirect, BlogPostRedirect, CategoryRedirect, and PageRedirect.
  • Under FOLLOW, node contains the target entity for a dynamic redirect. For a manual redirect, node is null and redirect supplies the details.
  • BigCommerce says GraphQL Storefront API queries run in the context of a particular storefront channel in its site-content documentation.

What does FOLLOW change in the route response?

The route node accepts a redirectBehavior argument. IGNORE is the default. It prioritizes a direct entity lookup through a custom URL, and the documentation says that both redirect and node can be non-null when a redirect and an entity URL share a path.

FOLLOW changes the value returned in node when the redirect is dynamic. The node becomes the target product, category, blog post, brand, or page, so the same GraphQL response can select fields from that entity. The redirect object remains available for the redirect metadata. BigCommerce's example returns a Product node with the target product's id and name alongside a ProductRedirect containing entityId and path.

The query shape in the documentation is:

query {
  site {
    route(path: "/mug" redirectBehavior: FOLLOW) {
      redirect {__typename to {__typename ...on ProductRedirect{entityId path}} toUrl}
      node {
        id
        ... on Product {
          name
        }
      }
    }
  }
}

How does a dynamic redirect expose its target?

A dynamic redirect points to an existing store resource by type and entity ID. The redirect.to object identifies the redirect subtype, while the subtype exposes fields such as entityId and path. The route query can then select the matching resource fragment in node, such as ... on Product { name }.

BigCommerce's GraphQL overview documents URL lookup for objects such as categories and brands and says that data for multiple resources can be returned from a single API call. That is the API context for reading the target entity directly in the FOLLOW response rather than first resolving a destination path.

The routes page lists five dynamic redirect types: ProductRedirect, BrandRedirect, BlogPostRedirect, CategoryRedirect, and PageRedirect. The entity fragment still has to match the target type. A product fragment cannot request category fields, for example, because GraphQL returns fields according to the concrete node type.

What details remain for a manual redirect?

A manual redirect has a fixed destination URL. With FOLLOW, BigCommerce returns null for node because a manual redirect has no associated entity, while redirect provides the redirect details. The example query selects toUrl and the ManualRedirect.url field:

redirect {
  toUrl
  to {
    ... on ManualRedirect {
      url
    }
  }
}

The destination URL is therefore data for a subsequent lookup. BigCommerce states that a new route query is needed to attempt to pull content at that destination, and that a destination which is itself a redirect can create a chain requiring multiple queries. The site-content guide also shows route lookup by page URL and states that the result is scoped to a particular storefront channel.

FAQ

What should you read after a dynamic redirect with FOLLOW?

Read the target entity in route.node, then use the matching GraphQL fragment for its concrete type. You can also read redirect.to for the dynamic redirect subtype and its entity identifier.

What does FOLLOW return for a manual redirect?

It returns null in node and keeps the fixed destination in redirect, including fields such as toUrl and ManualRedirect.url. You need another route query for the destination path.

Can you resolve a blog post with the same route pattern?

Yes. BigCommerce lists BlogPost as a possible route node type, and its site-content documentation describes retrieving blog posts using the web page URL.

Sources

  1. BigCommerce Docs, "Storefront Routes with the GraphQL Storefront API", Undated
  2. BigCommerce Docs, "GraphQL Storefront API overview", Undated
  3. BigCommerce Docs, "Site Content with the GraphQL Storefront API", Undated

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark