Skip to main content

Advanced Usage

This guide covers advanced SDK features for power users.

Custom GraphQL Client

The SDK comes pre-configured to use https://dao.cafe/graphql, but you can create custom clients for different scenarios.

Creating a Custom Client

Adding Request Headers

Modifying Default Client Headers

If you want to add headers to all requests globally:

Accessing the Default Client


Cache Invalidation

When using React hooks with TanStack Query, you can invalidate cached data to trigger refetches.

Basic Invalidation

Targeted Invalidation

Invalidate only specific queries for better performance:

Query Key Reference

ExportAvailable Keys
daoKeys.all, .lists(), .list(params), .byManager(params), .details(), .detail(id)
proposalKeys.all, .lists(), .list(params), .byDAO(daoId), .active(params), .details(), .detail(id)
voteKeys.all, .lists(), .list(params), .byProposal(id), .byVoter(voter), .details(), .detail(id)
delegateKeys.all, .lists(), .byDAO(daoId), .delegationsFrom(addr), .delegationsTo(addr), .details(), .detail(id)
tokenHolderKeys.all, .lists(), .byDAO(daoId), .byAddress(addr), .details(), .detail(id)

Error Handling

With React Hooks

TanStack Query provides built-in error handling:

With Query Functions

Use try/catch for promise-based functions:

Common Error Types

ErrorCauseSolution
Network ErrorNo internet / API unreachableCheck connection, retry
GraphQL ErrorInvalid query parametersCheck parameter types
Rate LimitToo many requestsAdd retry with backoff

Retry Configuration

Configure TanStack Query’s retry behavior:

Tree-Shaking

The SDK is designed for optimal bundle sizes. Only import what you need:

Bundle Size Tips

  1. Import specific hooks instead of entire modules
  2. Use type imports for TypeScript types
  3. React hooks are optional - if you don’t import them, they’re not bundled

Pagination

All list queries support cursor-based pagination:

Infinite Scroll with TanStack Query


Server-Side Rendering

For Next.js or other SSR frameworks, prefetch data on the server: