Skip to content
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

defaultOptions do not work #12247

Open
sanjiv-fusemachines opened this issue Dec 30, 2024 · 2 comments
Open

defaultOptions do not work #12247

sanjiv-fusemachines opened this issue Dec 30, 2024 · 2 comments
Labels
🏓 awaiting-contributor-response requires input from a contributor

Comments

@sanjiv-fusemachines
Copy link

Issue Description

The defaultOptions configuration is not functioning as expected when setting up the Apollo Client. Specifically, the fetchPolicy defined under defaultOptions.query is not being honored.

Apollo Client Version: @apollo/client 3.8.9

`ApolloClientFactory.apolloClient = new ApolloClient({

cache: new InMemoryCache(),
link: ApolloLink.from([
createMiddlewareContextLink(options?.middlewareContextLinkOptions),
...
]),

defaultOptions: {
query: { fetchPolicy: 'no-cache' },
},

ssrMode: !isBrowser(),

});`

Link to Reproduction

none

Reproduction Steps

  • defaultOptions is not working for mutation hooks generated by apollo client.
  • It only works when you explicitly send fetch-policy in the useCustomHookQuery({
    ...,
    fetchPolicy: "no-cache"
    }).

this works, but I think I don't think I need to set this explicitly. Anyone facing similar issue?

@apollo/client version

3.8.9

Copy link

triagster bot commented Dec 30, 2024

Related issues:

Was this useful? Use the thumbs up or thumbs down reaction to give feedback.

@phryneas
Copy link
Member

phryneas commented Jan 6, 2025

If you are using this with a hook like useQuery, you have to set the watchQuery default option, not the query one:

defaultOptions: {
-  query: { fetchPolicy: 'no-cache' },
+  watchQuery: { fetchPolicy: 'no-cache' },
},

@phryneas phryneas added the 🏓 awaiting-contributor-response requires input from a contributor label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏓 awaiting-contributor-response requires input from a contributor
Projects
None yet
Development

No branches or pull requests

2 participants