Company
Date Published
Author
Janessa Garrow
Word count
2130
Language
English
Hacker News points
None

Summary

The post explains how to set up Apollo Client with Remix, a newer JavaScript web framework that focuses on using native web APIs to improve the user experience. To do this, two key files are modified: `entry.server.tsx` and `entry.client.tsx`. In `entry.server.tsx`, an instance of `ApolloClient` is created with `ssrMode` set to true, a cache with `InMemoryCache`, and a link that uses `createHttpLink` instead of `uri`. The client is then wrapped in an `ApolloProvider` and passed to the `RemixServer` component. After the promise resolves, the cache value is extracted and set as the global object `__APOLLO_STATE__`. In `entry.client.tsx`, a new instance of `ApolloClient` is created with a URI and `InMemoryCache` that uses the `restore` function to rehydrate the browser's cache. The client is then wrapped in an `ApolloProvider` and passed to the `RemixBrowser` component. With these modifications, GraphQL requests can be made using Apollo Client's hooks, such as `useQuery`, in Remix pages and components.