Allow passing in a client object to the useFragment
hook
#407
Labels
🪝 react hooks
Feature requests related to React hooks
useFragment
hook
#407
I've loved using Apollo client's new
useFragment
hook these last few months! This feature request is about improving the flexibility (and possible performance) when using that feature.I'm currently in the process of trying to optimize a site for SEO where most pages don't have GraphQL queries that are being run unless the user is logged in. I'm using the new Apollo Provider from @apollo/experimental-nextjs-app-support for this:
My
getClient
function matches the example in the docs.Everything works, however this ends up negatively impacting the performance of the page. Loading just this part alone ends up being a long running task according to Google DevTools performance analysis.
This results in a lower Google PageSpeed Index, and lower SEO. Every little bit helps, but I'm not sure on other ways to optimize this aside from dropping the provider approach altogether. If anyone has alternative solutions, I'd love to hear them too.
Before
useFragment
, the solution would've been to remove the provider and just pass in the client touseQuery
everywhere while maintaining my own singleton for the request. That's more work than the provider, but it's doable.Right now
useFragment
uses theuseApolloClient()
hook to get the current client (and cache) from the Provider same asuseQuery
,useLazyQuery
anduseMutation
. However, all of those hooks take in an optionalclient
parameter, or use theclient
from the Provider if not provided.I'd like to request the
useFragment
hook have an optionalclient
argument that could be passed in similar touseQuery
,useLazyQuery
anduseMutation
? That would allow for dropping the global provider when usinguseFragment
.The text was updated successfully, but these errors were encountered: