Thanks @peterp
Ok I’m trying it out, it’s not yielding many results :-. Since I couldn’t see anything happening I digged a bit more in the doc and got some code from there which looks a lot like yours, a bit “enhanced” though.
I still don’t get results.
Two issues I’ve had:
- imports from your examples didn’t work, I had to use this:
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { createHttpLink } from 'apollo-link-http'
import { onError } from 'apollo-link-error'
- I configured an onError link but the outputs I’ve set within it are not being used:
const link = onError(({ graphQLErrors, networkError }) => {
alert('link works')
console.log(graphQLErrors, networkError)
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`#YOU^FAILED#[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
)
if (networkError) console.log(`#YOU^FAILED#[Network error]: ${networkError}`)
})
The #YOU^FAILED#
acts as a flag, messages would have been too generic…
Anyway! So this is not outputting anything, I went back to RW source code in packages/web
but since the code is super easy I would totally expect the config to be passed down to RW’s ApolloClient as it should.
That’s where I am now, figuring out if I can get some link added to RW’s configuration, covering not only the onError
case but also other links.
I knew nothing about them but there are also the awesome rest
link, context
and retry
, would be sweet to be able to tap into these :).
I’ll keep you posted if anything comes up! Meanwhile if you could space a couple of minutes to try something it would be great.
Last but not least: the cache doesn’t seem to be required but the doc sells it fairly: https://www.apollographql.com/docs/react/why-apollo/#zero-config-caching
I think it could deserve a note in RW’s doc, do you think it’s relevant?