import { gql, TypedDocumentNode } from '@apollo/client' import { useReadQuery } from '@apollo/client/react' import { createFileRoute } from '@tanstack/react-router' import React from 'react' // Example GraphQL query - replace with your own schema const EXAMPLE_QUERY: TypedDocumentNode<{ continents: { __typename: string; code: string; name: string } }> = gql` query ExampleQuery { continents { code name } } ` export const Route = createFileRoute('/demo/apollo-client')({ component: RouteComponent, loader: ({ context: { preloadQuery } }) => { // Preload the query in the loader for optimal performance const queryRef = preloadQuery(EXAMPLE_QUERY, { variables: {}, }) return { queryRef, } }, }) function RouteComponent() { const { queryRef } = Route.useLoaderData() const { data } = useReadQuery(queryRef) return (
Apollo Client is configured!
This demo uses{' '}
preloadQuery in the
loader and{' '}
useReadQuery in the
component for optimal streaming SSR performance.
{JSON.stringify(data, null, 2)}
📝 Next steps:
src/router.tsx