apollo-client-devtools: Cannot read property 'queryStore' of undefined, cannot convert null or undefined to object, unsafe-eval is not allowed source of script in the following CSP
npm ls --depth=0 | grep apollo
├── apollo-cache-inmemory@1.1.5
├── apollo-client@2.2.1
├── apollo-fetch@0.7.0
├── apollo-link-batch-http@1.0.4
├── react-apollo@2.0.4
Hey, In our project apollo-client-devtools stopped working. In the console inside the app, there is a reported error:
which is:
Also when I try to debug apollo devtools, in their console are reported errors below (here devtools has disappeared):
Is this something that we should fix on the our side? Many thanks.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 27
- Comments: 23
Same issue
Chrome version: 71.0.3578.98
@peggyrayzis any updates here? Seems this issue has been here since Feb and no devs from the Apollo team have commented on the thread.
In my case, using React Router causes this issue. Adding
client.initQueryManager()
just makes the error disappear but the problem persists. When I click cache I see an empty page. If I close and re-open the Devtools I can see the cache. So, does React Router cause a second initialization of the client here?@ananth99 No, I literally meant 2 instances not the version 2! I believe the dev tools got confused having 2 clients on the same website, it worked for me when I didn’t load the script tag of one of them
Just a few clues… indeed it seems that ApolloClient.queryManager is not getting set. You can verify this by typing
window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__
in your console prompt.I stepped through some Apollo source code a bit. If you look at the source for ApolloClient (https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/ApolloClient.ts ) , you can see that there is a public method
initQueryManager()
. I tried adding a call to that method after creating my client:client.initQueryManager()
.After doing that, I no longer see the error regarding
queryStore
. However, apollo-dev-tools still doesn’t work - it disappears when I click on the Cache tab.Looking at the source for ApolloClient more closely, you can see that it’s constructor doesn’t call
initQueryManager
. Rather, certain methods such asmutate
,query
, orsubscribe
call it. I don’t know why it shouldn’t be done in the constructor. As it is, unless your app starts off with a query (or some operation that triggers a call toinitQueryManager
) immediately, thenApolloClient.queryManager
will be undefined and so the dev tool won’t work.Same here with regular default installation that uses
InMemoryCache
with default settings