-
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Adding apollo dev tools. #298
Conversation
Hi, great to see you're trying to implement this! Initially I hope it will be included in tabs of I just worried about some performance issues for this implementation, we can try improving it in the future.
If possible, we could try to import the backend bundle, or just install |
Hey @jhen0409, I will take a look how much has to be changed to support apollo dev tools backend out of the box for the debugger. I hope to get back with some news sometime this week :) |
…ools code in the debugger.
…connecting the debugger. Only displays apollo tab if apollo is added inside the project.
Hey @jhen0409, This way we will only have to add minimal amount of code inside the react native debugger itself. Mainly we will have to add code inside Maybe I will add most of the code in webworker to apollo dev tools themselves, so we could import instead of having it in this project. I will talk about it with someone from apollo team. Hope to have some more news in next few days |
Hey @jhen0409, I am still waiting from apollo side to publish dev tools as a npm module. When it is published we can move forward. |
# Conflicts: # app/middlewares/debuggerAPI.js # app/worker/index.js
…ndow... they have to be separate.
@@ -24,7 +24,8 @@ | |||
"__PLATFORM__", | |||
"__REPORT_REACT_DEVTOOLS_PORT__", | |||
"__FETCH_SUPPORT__", | |||
"__NETWORK_INSPECT__" | |||
"__NETWORK_INSPECT__", | |||
"__APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apollo dev tools are not displayed in the chrome dev tools by default.
It tries to check if window.apolloClient is set. Because we don't have apollo client in window (it is in web worker), I've created a separate bool for it.
app/middlewares/debuggerAPI.js
Outdated
@@ -32,6 +32,18 @@ let socket; | |||
|
|||
const workerOnMessage = message => { | |||
const { data } = message; | |||
|
|||
if (data && data.source === 'apollo-devtools-backend') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we get at least one message from apollo backend (the code in the worker) it means that apollo client is being used in the app. So we tell apollo dev tools to display its panel in chrome dev tools.
Also we forward the message from webworker to react native debugger web part.
app/middlewares/debuggerAPI.js
Outdated
@@ -43,14 +55,22 @@ const workerOnMessage = message => { | |||
socket.send(JSON.stringify(data)); | |||
}; | |||
|
|||
const onWindowMessage = e => { | |||
const {data} = e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we receive data from panel in web part, we forward the message to the worker. There are some checks for payload, but they are there since apollo dev tools don't strictly follow api for event emitter.
app/worker/index.js
Outdated
@@ -51,6 +53,46 @@ const setupRNDebugger = async message => { | |||
checkAvailableDevMenuMethods(modules, message.networkInspect); | |||
reportDefaultReactDevToolsPort(modules); | |||
} | |||
|
|||
const interval = setInterval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apollo client doesn't have any event emitted when it is set up. To overcome that I just poll the client till it appears.
It is not an optimal approach, but simple polling shouldn't be too much overhead
app/worker/index.js
Outdated
|
||
let listener; | ||
|
||
const bridge = new Bridge({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code to forward messages received from post message to event emitter for apollo
Hey, @jhen0409, Now I am just waiting for apollo to publish npm package and answer me one question. |
app/worker/asyncStorage.js
Outdated
@@ -3,6 +3,24 @@ export const getClearAsyncStorageFn = AsyncStorage => { | |||
return () => AsyncStorage.clear().catch(f => f); | |||
}; | |||
|
|||
export const getSafeAsyncStorage = AsyncStorage => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes Async storage throws errors, we want to silence them
This is a relevant issue in apollo dev tools apollographql/apollo-client-devtools#160 |
@jhen0409, and we are ready to go! All the changes from the apollo team were published. Could you review the code some time in around? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I think it's ready to merge. Thanks!
@Gongreg, I also added you as collaborator.
Awesome @jhen0409, can you ping me when you release an updated version? Also thank you for adding me as a collaborator, I will try to help from time to time, since I use this debugger daily and suggest it for everyone else :) |
@Gongreg, OK, I'll comment to apollographql/apollo-client#4386 when it is released. :) @Aleksion, It seems to |
Adding apollo dev tools.
Hey, @jhen0409, I wasn't sure how to get in contact with you to discuss apollo dev tools integration, so I will just open the pull request here.
I wanted to talk with you about how we could do a proper integration.
Currently what I do is I add some apollo code that is waiting to get apollo client in the app inside the worker which runs actual app code.
I also add apollo tab inside dev tools.
I think it could be possible not to leak any apollo code to react native debugger by using importScripts command?
Maybe we could have a chat in slack or discord to fully discuss this thing?