Data Fetching
API Client
The API client is the primary way to send queries and mutations to the Vendure backend. It handles channel tokens and authentication automatically.
Importing the API Client
The API client exposes two main methods:
query- For GraphQL queriesmutate- For GraphQL mutations
Using with TanStack Query
The API client is designed to work seamlessly with TanStack Query for optimal data fetching and caching:
Query Example
Mutation Example
Type Safety
The Dashboard Vite plugin incorporates gql.tada, which gives you type safety without any code generation step!
It works by analyzing your Admin API schema (including all your custom fields and other API extensions), and outputs the results
to a file - by default you can find it at src/gql/graphql-env.d.ts.
When you then use the import { graphql } from '@/gql' function to define your queries and mutations, you get automatic
type safety when using the results in your components!
When you have the @/gql path mapping correctly set up as per the getting started guide, you should see that
your IDE is able to infer the TypeScript type of your queries and mutations, including the correct inputs and return
types!
