Apollo Client - Can I conditionally set/switch a fetchPolicy

Hi all,

Is it possible to set/switch a fetchPolicy let’s say from network-only to cache-and-network using a ternary operator e.g

const userAction = true
const randomQuery = useQuery(RANDOM_QUERY,{
fetchPolicy: userAction ? 'network-only': 'cache-and-network'
})

I don’t see a reason why that should not be possible. Have you tried it?

1 Like