December 14, 2022

Create an omnichannel shopping experience with GraphQL

Shane Myrick
@shanemyrick
Last updated January 10, 2023

This post is a part of our “How to power modern retail apps with Apollo GraphOS” series. Also in this series:


“Omnichannel” has become the go-to term to describe how data is shared across your company so customers will have a unified experience interacting with all parts of your business—from social marketing to the digital or physical marketplace.

Because Apollo GraphOS is the go-to platform for providing a unified API experience to clients apps by connecting all of your data sources in a supergraph, it’s a perfect fit for creating omnichannel experiences. Let’s dive into how you can accomplish that with GraphQL.

Federating a supergraph schema

A federated GraphQL architecture splits services into subgraphs so that each team can own a smaller, more focused domain, while still providing a single, unified supergraph schema for all of your clients to consume. This means that your client teams—whether they work on the website, mobile apps, chatbots, or POS systems—can all use the same API to accomplish their specific goals.

Omnichannel revolves around connecting all data sources back to your user, so ideally, you have a user ID that can be used across all channels or a way of converting it in each channel. We can define that user in a subgraph schema as follows:

# Users subgraph

type User @key(fields: "id") {
  id: ID!
}

By setting the id as the key field using the @key directive, we have turned the User object type into an entity so any other subgraph can now add fields to the User type or return the User from any of their fields, and all they need to know about a specific user is their ID.

For example, in the separate subgraph for a checkout service, we can add a cart field on the User by extending it like so:

# Checkout subgraph

type User @key(fields: "id") {
  id: ID!

  "The user's active cart session"
  cart: Cart
}

As more and more subgraphs extend additional fields on the User type, client developers will be able to see the full representation of the User type which will give them the ability to create intricate queries that span across many subgraphs, such as getting all the items a user has ordered or put in their cart so we can craft a targeted marketing email.

Loyalty across channels

An effective omnichannel strategy involves tracking when a user is moving across all your channels and which actions they take in each one. Creating a federated supergraph allows each channel to operate independently to report user actions and scale out based on their runtime or development needs.

A common strategy usually involves offering rewards or discounts to users for shopping in different channels or tracking where they have previously purchased products. We could try to calculate this infomation in each client by looking at previous orders, but with a supergraph architecture we can add this functionality to our existing API without breaking our current clients:

# Users subgraph

type User @key(fields: "id") {
  id: ID!
  loyalty:LoyaltyProgram
}

type LoyaltyProgram {
    activeDiscounts: [Discount]
    joinedDate: Date
    points: Int
}

By adding these new fields we can look at all of our active discounts when querying for user data across all channels. We can even use the graph itself to add more discounts to our users in an offline process, like querying for their loyalty start date and adding a discount on their anniversary or making sure our systems don’t offer overlapping or duplicate discounts to the users.

Get started with a retail supergraph today

Beyond realizing the potential of an omnichannel shopping experience, the best way to see the possibilities of a supergraph is to try one out. You can explore a retail supergraph schema and run real queries against it here.

We also have additional posts in this series of retail best practices that dive into different elements of this schema to illustrate how Apollo GraphOS help power essential features of modern retail applications.

If you’d like to talk to an Apollo expert about how a supergraph can power your retail experience, please reach out to us.

Written by

Shane Myrick

Follow

Stay in our orbit!

Become an Apollo insider and get first access to new features, best practices, and community events. Oh, and no junk mail. Ever.

Make this article better!

Was this post helpful? Have suggestions? Consider so we can improve it for future readers ✨.

Similar posts

January 4, 2023

Add Rust to your GraphQL API with GraphOS

by Dylan Anthony

Company