Skip to content

Adding code necessary for React Native support - #165

Merged
cheapsteak merged 7 commits into
apollographql:masterfrom
Gongreg:apollo
Jan 25, 2019
Merged

cheapsteak merged 7 commits into
apollographql:masterfrom
Gongreg:apollo

Conversation

@Gongreg

@Gongreg Gongreg commented Jan 9, 2019

Copy link
Copy Markdown
Contributor

In React Native debugger we create our own Bridge that we want to use with apollo dev tools.
I've updated the code to allow to setup custom bridge.

The main question I have is uuid in check versions is used for? This code is not easy to implement in React Native, since it doesn't have localStorage but instead asyncStorage which is, well, async.

Of course for RN we also need to solve #160.

Displays panel if __APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__ is set to true.
Moved out hook to the backend files, so we could reuse src/backend/index in react native too.
# Conflicts:
#	shells/dev/src/backend.js
#	shells/webextension/src/backend.js
@apollo-cla

Copy link
Copy Markdown

@Gongreg: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

Comment thread src/backend/checkVersions.js Outdated
}
let uuid = genUuid();

export const checkVersions = (hook, bridge) => {

@benjamn benjamn Jan 9, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main question I have is uuid in check versions is used for? This code is not easy to implement in React Native, since it doesn't have localStorage but instead asyncStorage which is, well, async.

It seems like checkVersions ultimately does an async fetch call, so perhaps we could store the uuid using a generic async local storage API (backed by sync localStorage in browsers, but asyncStorage in RN), and then just hide the async access within the already-async behavior of checkVersions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea @benjamn, I will implement it today!

@Gongreg

Gongreg commented Jan 10, 2019

Copy link
Copy Markdown
Contributor Author

Hey, @benjamn,
I've updated the code. I see that for devtools version the version is taken out of manifest.json.

I am not sure it is the right thing to do to try to get it the same way in react native.
So what I assume is that the version will be in package.json (since it has to have a version). Is that okay?

@cheapsteak cheapsteak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 👍
Would appreciate if you could add a few comments to clarify some things that might not make sense unless you think about the package as something that'll be imported from somewhere else 🙏

Comment thread src/backend/index.js
let connected;
let storage;

export const sendBridgeReady = () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment here to explain why this function exists and is exported instead of inlined into the call site 🙏? I assume this is so the react native debugger can import and call this :)

panelShown = false;
chrome.devtools.inspectedWindow.eval(
`!!(window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__.ApolloClient);`,
`!!(window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__.ApolloClient || window.__APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__);`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment here as well to explain what __APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__ is?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, since there is no Apollo client in the window context of react native debugger (the react native code with apollo is ran in a separate worker), we can't check for APOLLO_DEVTOOLS_GLOBAL_HOOK. To make it explicit I add a separate flag.

@Gongreg

Gongreg commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

Hey @cheapsteak, I've added the comments :)

@cheapsteak cheapsteak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the contribution!
Looking forward to seeing this work with React Native Debugger :D
Do we need to publish a new version to npm after merging?

@Gongreg

Gongreg commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

Yea, that would be great.
Then I will do final checks with the react native debugger itself and it should be good to go :)

(I've worked on two projects, while doing changes both in checked out projects and in node_modules, in two different machines, so there is a big chance I might have missed something :D)

Can you notify me when the new npm version is published?

@cheapsteak

Copy link
Copy Markdown
Contributor

That sounds great :D
Yup I can do that

@cheapsteak
cheapsteak merged commit cc05e07 into apollographql:master Jan 25, 2019
@cheapsteak

Copy link
Copy Markdown
Contributor

@Gongreg published under 2.1.7-alpha.0 for now for testing 🙏

@Gongreg

Gongreg commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

hey @cheapsteak, seems like the release didn't go well. I still get the code without the PR in 2.1.7-alpha.0 .

https://registry.npmjs.org/apollo-client-devtools/-/apollo-client-devtools-2.1.7-alpha.0.tgz

@cheapsteak

cheapsteak commented Jan 25, 2019 •

Copy link
Copy Markdown
Contributor

@Gongreg apologies, my bad 🤦‍♂️
just published alpha.1

@Gongreg

Gongreg commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

@cheapsteak Just tested things out. It works! :) Going to try to get the react-native-debugger pr to be merged as soon as possible :)

@Gongreg
Gongreg deleted the apollo branch January 25, 2019 22:19
@Gongreg

Gongreg commented Jan 25, 2019

Copy link
Copy Markdown
Contributor Author

@cheapsteak , one more issue. We need to have dist directory in shells/webextension, since we use the panel in react native debugger.

@cheapsteak

Copy link
Copy Markdown
Contributor

Ah, that makes sense
We could probably add that as a prepublish hook, and also add it to gitignore
You might have more familiarity with this repo than Justin and I do at the moment 😛, do you know if running the build script would be sufficient? Or would we need to add a new script?

@Gongreg

Gongreg commented Jan 28, 2019

Copy link
Copy Markdown
Contributor Author

Truth to be told I don't know which option is better. I've never worked on the module before this PR. But adding it as a build step sounds reasonable.

I will create a separate issue and assign you, so it wouldn't be forgotten.

@justinanastos

Copy link
Copy Markdown
Contributor

#169

@cheapsteak

Copy link
Copy Markdown
Contributor

Published alpha.2 that includes the dist folder
https://unpkg.com/apollo-client-devtools@2.1.7-alpha.2/shells/webextension/dist/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants