Saleor GraphQL API Frontend Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1 servicesAll 2065 services
Saleor GraphQL API Frontend Integration
Medium
~5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Integrating Saleor GraphQL API with Frontend

Saleor provides a single GraphQL endpoint for all operations — catalog, cart, checkout, payments, account. The frontend works directly with this API without an intermediate REST layer. Integration is built on Apollo Client or urql, with type generation via @graphql-codegen.

Setting Up Apollo Client

// lib/apolloClient.ts
import {
  ApolloClient,
  InMemoryCache,
  createHttpLink,
  from,
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { onError } from "@apollo/client/link/error";

const httpLink = createHttpLink({
  uri: process.env.NEXT_PUBLIC_SALEOR_API_URL,
});

const authLink = setContext((_, { headers }) => {
  const token = localStorage.getItem("saleor_token");
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : "",
    },
  };
});

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.forEach(({ message, extensions }) => {
      if (extensions?.code === "AUTHENTICATION_FAILED") {
        localStorage.removeItem("saleor_token");
        window.location.href = "/login";
      }
    });
  }
});

export const client = new ApolloClient({
  link: from([errorLink, authLink, httpLink]),
  cache: new InMemoryCache({
    typePolicies: {
      Product: { keyFields: ["id"] },
      ProductVariant: { keyFields: ["id"] },
      Checkout: { keyFields: ["id"] },
    },
  }),
});

Type Generation via Codegen

# codegen.yml
overwrite: true
schema: "https://api.your-store.com/graphql/"
documents: "src/**/*.graphql"
generates:
  src/generated/graphql.ts:
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      withHooks: true
      withComponent: false
      scalars:
        JSON: "Record<string, unknown>"
        Date: "string"
        Decimal: "string"
        UUID: "string"
        PositiveDecimal: "number"
npx graphql-codegen --config codegen.yml

Result — fully typed hooks like useProductListQuery, useCheckoutCreateMutation, etc.

Catalog: Product List with Pagination

# queries/products.graphql
query ProductList(
  $first: Int
  $after: String
  $filter: ProductFilterInput
  $channel: String!
) {
  products(first: $first, after: $after, filter: $filter, channel: $channel) {
    edges {
      node {
        id
        name
        slug
        thumbnail { url alt }
        pricing {
          priceRange {
            start { gross { amount currency } }
          }
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
const { data, fetchMore } = useProductListQuery({
  variables: { first: 24, channel: "default-channel" },
});

const loadMore = () => {
  fetchMore({
    variables: { after: data?.products?.pageInfo.endCursor },
    updateQuery: (prev, { fetchMoreResult }) => {
      if (!fetchMoreResult) return prev;
      return {
        products: {
          ...fetchMoreResult.products,
          edges: [
            ...prev.products!.edges,
            ...fetchMoreResult.products!.edges,
          ],
        },
      };
    },
  });
};

Checkout Flow

Saleor separates checkout into explicit mutations. Full flow:

// 1. Create checkout
const [createCheckout] = useCheckoutCreateMutation();
const { data } = await createCheckout({
  variables: {
    input: {
      channel: "default-channel",
      lines: [{ variantId, quantity: 1 }],
      email: "[email protected]",
    },
  },
});
const checkoutId = data?.checkoutCreate?.checkout?.id;

// 2. Add shipping address
const [updateShippingAddress] = useCheckoutShippingAddressUpdateMutation();
await updateShippingAddress({
  variables: {
    id: checkoutId,
    shippingAddress: {
      firstName: "Ivan",
      lastName: "Petrov",
      streetAddress1: "ul. Lenina 1",
      city: "Moscow",
      country: CountryCode.Ru,
      postalCode: "101000",
    },
  },
});

// 3. Select shipping method
const [updateDelivery] = useCheckoutDeliveryMethodUpdateMutation();
await updateDelivery({
  variables: { id: checkoutId, deliveryMethodId: shippingMethodId },
});

// 4. Create payment
const [createPayment] = useCheckoutPaymentCreateMutation();
await createPayment({
  variables: {
    id: checkoutId,
    input: {
      gateway: "mirumee.payments.stripe",
      token: stripeToken,
      amount: checkoutTotal,
    },
  },
});

// 5. Complete order
const [completeCheckout] = useCheckoutCompleteMutation();
const order = await completeCheckout({ variables: { id: checkoutId } });

User Authentication

// Login
const [tokenCreate] = useTokenCreateMutation();
const { data } = await tokenCreate({
  variables: { email, password },
});
const { token, refreshToken, errors } = data!.tokenCreate!;

if (!errors?.length) {
  localStorage.setItem("saleor_token", token!);
  localStorage.setItem("saleor_refresh_token", refreshToken!);
}

// Token refresh
const [tokenRefresh] = useTokenRefreshMutation();
const refreshed = await tokenRefresh({
  variables: { token: localStorage.getItem("saleor_refresh_token")! },
});

Error Handling in Saleor

Saleor returns errors not via standard GraphQL errors, but through the errors field in the mutation response body. Handling pattern:

function handleSaleorErrors<T extends { errors: SaleorError[] }>(
  result: T | null | undefined,
  onSuccess: (data: T) => void
) {
  if (!result) return;
  if (result.errors.length > 0) {
    result.errors.forEach((err) => {
      console.error(`${err.field}: ${err.message} (${err.code})`);
    });
    return;
  }
  onSuccess(result);
}

Performance

  • Saleor supports persisted queries — send hash instead of query text
  • Use fragments for reusing fields across queries
  • InMemoryCache with proper keyFields prevents data duplication
  • For SSR (Next.js) — @apollo/experimental-nextjs-app-support or getStaticProps with client.query()

Integration Timeframes

Stage Timeframe
Apollo Client setup + codegen 1 day
Catalog (list, filters, product page) 2–3 days
Cart + checkout (no payment) 2–3 days
Payment gateway (Stripe/Adyen) 2–3 days
User account, order history 1–2 days