-
Notifications
You must be signed in to change notification settings - Fork 844
feat: gremlin-javascript browser support
#2506
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
Conversation
|
Hey guys, would love to get this working in an environment outside of Node.js. I think this would boost adoption greatly, as a lot of serverless runtimes (i.e. Cloudflare Worker, Vercel, etc) now utilise standard Web APIs. This is just something I draft quickly together with the limited knowledge that I have. Would appreciate any helps & guidances. 🙏 |
9e5f8cc to
b6c7bbc
Compare
gremlin.js browser supportgremlin.js browser support
|
Thanks for you interest in contributing. There has been a lot of interest around adding this support in the past. This is the open Jira issue for reference https://issues.apache.org/jira/browse/TINKERPOP-2143. The past attempts seem to have run into some issues with tests #1070 and #1291. I'm not familiar with JavaScript so I'll try to have someone that is look into this. Thanks again. |
gremlin.js browser supportgremlin-javascript browser support
|
@kenhuuu thanks for getting back & reminding me about the integration test, I was able to run it locally and have all tests passed. For actually running in a browser API compatible environment, I've tested this on my application running on Cloudflare Worker & everything so far works as expected. |
49685dc to
0ab2884
Compare
|
Have also just tested & fix bugs when running this in an actual browser. Everything seems okay so far. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 3.7-dev #2506 +/- ##
=============================================
+ Coverage 76.14% 76.49% +0.35%
- Complexity 13152 13170 +18
=============================================
Files 1084 1059 -25
Lines 65160 61270 -3890
Branches 7285 7295 +10
=============================================
- Hits 49616 46869 -2747
+ Misses 12839 11888 -951
+ Partials 2705 2513 -192 ☔ View full report in Codecov by Sentry. |
|
Forgot that But optionally we can change the supported node version to LTS, which is 20 right now if you guys think that is best. |
7143e35 to
3b4a63d
Compare
|
Hmm, looks like the |
It's against our current runtime policy (https://tinkerpop.apache.org/docs/current/dev/developer/#runtimes) to upgrade unless the supported runtime has reached end of life. If you feel that it would really be worth it to upgrade to Node 20 then it's a conversation you could start on the dev-list.
I think that makes sense to ignore it then. |
|
@kenhuuu Regarding the Node version, whatever make sense to you guys, of course. It's not a major deal. But I think the wording in the link that you shared could be a bit better:
It's not clear whether that mean supporting the current LTS version, which is 20. Or supporting previous version that hasn't reached end of life yet, which is 18. |
gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
Outdated
Show resolved
Hide resolved
|
@vkagamlyk the proper way would be to actually run the unit tests in the browser, like @kmcginnes mentioned. But that could potentially be a huge change to the current test suite. Another way would be to inject a browser |
|
@vkagamlyk also, because the API signature is the exact same, those existing examples can be run just fine in a browser environment. |
|
@vkagamlyk or are you suggesting I should create like a simple html page that simply run all the stuffs under |
I thought about something more simple, like html page which runs single query like |
|
Okay I'll add a simple webpage. There's some flaky test that is failing randomly on GitHub Action it seems btw. |
|
@vkagamlyk have added a simple webpage that just display your graph running on |
|
Modified the README a bit to say this is also compatible with Web APIs compatible runtimes (browsers, WinterCG runtimes, etc) |
|
@tien I got an error |
Is this from running the example? To run the example, you need to do this at yarn
yarn dev |
|
|
VOTE +1 |
Thanks 🙏, just made a small change, updating the browser example package.json description. |
|
@kenhuuu regarding the user agent header used by Gremlin server This is likely a separate discussion, but What might be better is using the new WebSocket("ws://localhost:8182", "glv3.7");The sub-protocol can even be registered here if needed :)) |
Thanks for the information. As I mentioned above, we'll be moving to HTTP only in 4.x so its probably best to keep the 3.x WebSocket behavior the same for now. |
|
VOTE +1. Thanks again for your willingness to contribute. It is much appreciated. I'm not sure if you are familiar with our policy but it takes a VOTE+1 from three different committers to allow a PR to get merged immediately. Otherwise, if you get at least one of them (you have two right now), then the PR can be merged one week after the first VOTE +1. So at the latest this PR will be eligible for merging on Monday of next week. |
|
@kenhuuu thanks for this. I'll try to find another VOTE +1 if possible. Would be beneficial for me to get this in early because there's a work project I'm on that's currently using this. |
|
Thanks for putting all of this together @tien, that's awesome that gremlin-javascript will now work in browsers and I think having that simple little visualizer as an example is really cool. I do have a slight apprehension towards advertising full support for browser runtimes without a proper test suite for it. How would you feel about changing the wording in the readme to something such as |
- Replace node APIs that have cross runtime equivalent - For those that can't be replaced, use `node:` prefix so that environment that does polyfill automatically can easily do so - Remove manual ping/pong logic, this is already handled internally by browser or `ws` library
|
@Cole-Greer Yeah I think that make sense, have changed the README accordingly. |
|
Thanks @tien, I think this is great. VOTE +1. I will merge this into both 3.7-dev and master so it will be reflected in the upcoming 3.7.2 and 4.0.0 releases. Just to set some expectations on release timelines, no discussion has yet taken place on when the 3.7.2 release will take place, but based on historical release timing, we typically see a release in the rough April-May window. I would expect that discussions around the next release will begin to take place in the dev maillist sometime within the next couple of weeks. |
I hadn't checked my email just yet when I wrote this, looks like the release discussion has just started. The current proposal is for a early April release. https://lists.apache.org/thread/8vvo6f74lo1tb7pzclo1pwqbv6xrncl3 |

node:prefix so that environment that does polyfill automatically can easily do sowslibrary + WhatWGWebSocketAPI doesn't have ability to do manual ping/pong