-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remix #248
Comments
Thoughts on LoadersLoaders run independently of React.
As a result, our current "inject into the stream" approach won't work - we have no way of sharing an AC instance reliably between => each loader should create their own instance of Apollo Client and const loader = () => {
const preload = createQueryPreloader(makeClient())
const result1 = preload(query1)
const result2 = preload(query2)
return defer({
result1,
result2
})
} Now, right now So we probably need to wrap It could create a value like {
query,
variables,
resultPromise
} which would then be picked up by an (also wrapped) Currently, the defer implementation doesn't support promises that are not on the top level yet. We'd probably need buy-in from the Remix team here to be able to make according changes on their side - once we have fleshed out this story more. |
Hi @phryneas, I was trying to get the transported data stored locally to the cache and I came up with below... It does do what I intend it to but I am wondering if this is how you would go about it. Thanks for any direction :) // makeClient.ts
import { HttpLink } from "@apollo/client/index.js";
import { ApolloClient, InMemoryCache } from "@apollo/client-react-streaming";
import { CachePersistor } from 'apollo3-cache-persist';
export const cache = new InMemoryCache()
const persistor =
typeof window !== 'undefined'
? new CachePersistor({
cache,
storage: localStorage,
})
: null;
persistor &&
persistor.restore().then(() => {
// console.log('cache restored')
});
export function makeClient() {
return new ApolloClient({
cache: typeof window === 'undefined' ? new InMemoryCache() : cache,
link: new HttpLink({
uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
}),
});
} |
@LydiaF It seems okay, although I would probably question if this is necessary at all - if you use this package to it's full extend, every page should bring their data to the cache anyways. Also, you probably shouldn't be creating an I do wonder though, why are you posting this in the Remix issue? This doesn't seem to add to that topic. |
Hi @phryneas, thank you for replying so quickly and for your help. I think I am okay now. I think I was confused because I was still thinking in terms of how I used to do things -- I would look in Application local storage to see the cache data (as opposed to Apollo dev tools), and would also typically import the cache to do something like below as opposed to using useApolloClient. So I was lost as to how to call methods on the cache and then wrongly thought the data was somehow not really there. // app/routes/_index.tsx
export default function Index() {
const client = useApolloClient();
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<button
onClick={() => {
client.cache.updateQuery({ query: ALL_FILMS }, (data) => ({
allFilms: {
__typename: "FilmsConnection",
films: [],
},
}));
}}
>
Press Me
</button>
<Suspense fallback="loading">
<Suspended />
</Suspense>
</div>
);
} As for posting here, apologies, I probably should have asked in the repo you made. Thanks again! |
Hi @phryneas - I came across this issue whilst trying to get the Apollo From what I can see, it seems that the Remix SSR and Apollo's I can workaround by breaking my graph query up into the fast and slow parts like below, however that loses some of the simplicity of the having the Apollo Am I missing any other way of getting Apollo
|
Hi @harryblam! We're currently working on an integration for React Router 7 that should work with defer in loaders. You can install the current version via npm i https://pkg.pr.new/apollographql/apollo-client-nextjs/@apollo/client-integration-react-router@419 and follow these instructions https://github.com/apollographql/apollo-client-nextjs/blob/next/packages/react-router/README.md As far as I know, React Router 7 is the successor to Remix, so I don't know if this is already applicable with old Remix setups - you would need to activate at least their "single fetch" behaviour. I'd be happy to hear feedback :) |
thanks for getting back @phryneas! Good to know about React Router 7, are you guys also working on that integration over at the https://github.com/apollographql/apollo-client repo? |
@harryblam all the streaming SSR implementations for different frameworks will live in this repo for now, as React still doesn't provide us the primitives to create a framework-agnostic solution. But we should probably rename this repo at some point 😅 |
First the good news: streaming SSR with the suspense hooks and Remix works.
All the setup for that is in this diff: phryneas/remix-apollo-stream-example@bc43efe
That said, supporting loaders is another beast.
I'll add my thoughts in this thread.
The text was updated successfully, but these errors were encountered: