For what it’s worth I did give apollo-client-integrations/packages/tanstack-start at main · apollographql/apollo-client-integrations · GitHub a try but to no avail. Here is my implementation if @lenz wanted to give it a glance.
client.ts
import { createQueryPreloader } from '@apollo/client';
import { ApolloClient, InMemoryCache } from '@apollo/client-integration-tanstack-start';
export const client = new ApolloClient({
cache: new InMemoryCache(),
});
export const preloadQuery = createQueryPreloader(client);
router.ts
import { createRouter as createTanStackRouter } from '@tanstack/react-router';
import { routeTree } from './routeTree.gen';
import { routerWithApolloClient } from '@apollo/client-integration-tanstack-start';
import { createQueryPreloader } from '@apollo/client';
import { client } from './providers/le-apollo-provider/client';
export function createRouter() {
const router = createTanStackRouter({
routeTree,
defaultPreload: 'intent',
scrollRestoration: true,
defaultStructuralSharing: true,
// Let Apollo handle caching in loaders instead of Tanstack Router https://tanstack.com/router/v1/docs/framework/react/guide/preloading#preloading-with-external-libraries
defaultPreloadStaleTime: 0,
context: {
// auth will initially be undefined
// We'll be passing down the auth state from within a React component
auth: undefined!,
apolloClient: client,
preloadQuery: createQueryPreloader(client) as any, <--- Couldn't find the correct type for this
},
});
return routerWithApolloClient(router, client);
}
// Register the router instance for type safety
declare module '@tanstack/react-router' {
interface Register {
router: ReturnType<typeof createRouter>;
}
}
app.ts
import { RouterProvider } from '@tanstack/react-router';
import Auth0Provider from './providers/auth0-provider';
import { createRouter } from './router.ts';
import { useAuth0, User } from '@auth0/auth0-react';
import ApolloProvider from './providers/apollo-provider/apollo-provider.tsx';
function InnerApp() {
const auth = useAuth0();
if (auth.isLoading) {
return null;
}
return (
<RouterProvider
router={createRouter()} <-- using the client-integration-tanstack-start router
context={{
// There should always be an ID (sub)
auth: auth as ReturnType<typeof useAuth0<User & { sub: NonNullable<User['sub']> }>>,
}}
/>
);
}
export default function App() {
return (
<Auth0Provider
...
>
<ApolloProvider>
<InnerApp />
</ApolloProvider>
</Auth0Provider>
);
}
$dealId.ts
...
loader: ({ params, context }) => {
return context.preloadQuery(DealQuery, {
variables: { dealId: params.dealId },
});
},
...
const dealQueryRef = Route.useLoaderData();
console.log({ dealQueryRef });
const { data } = useReadQuery(dealQueryRef);
This console.log
would give me alternating responses between

and

The latter giving me the
Error message
Expected a QueryRef object, but got something else instead.
when I tried to use the queryRef
in the useReadQuery
tldr; There was no difference for me in outcome when using the @apollo/client-integrations-tanstack-start
and just using @apollo/client
Just to reiterate I am using Vite with React and just TanStack Router, not TanStack Start.
Do you want me to also post this on that github issue you linked?