platform support
cleve-fauna opened this issue ยท 3 comments
Axios hems us into a limited set of platforms. Re-evaluate http layer dependencies to support platforms including:
Cloudflare, Vercel Edge and Serverless functions, Web Assembly, the Deno runtime, AWS Lambda, Netlify Functions
Hi guys,
@breinero shared with me the early access of 'fauna-js'. First of all, I want to say that you're doing an excellent job - I can already feel how much faster we will get with FQL.X!
We're currently integrating fauna-js into Cloudflare Workers and running into the Axios incompatibility problem. So I asked @breinero if you're open to some contributions. He said yes, so here I am ;)
We're currently creating a forked version of fauna-js where we replace Axios with fetch(). Fetch seems to be the best option to achieve support for all the major JS runtimes and providers.
I created a list on the compatibility of fetch()
:
WebAPI | Node 18 | Node 17> | Deno | Bun | |
---|---|---|---|---|---|
Browser | fetch() | N/A | N/A | N/A | N/A |
Cloudflare Workers | fetch() | N/A | N/A | TODO | N/A |
Vercel Edge (Cloudflare Workers) | fetch() | N/A | N/A | TODO | N/A |
Vercel Serverless functions | N/A | fetch() | Isomorphic Unfetch / Cross-fetch | fetch() | fetch() |
Cloud Functions | N/A | fetch() | Isomorphic Unfetch / Cross-fetch | fetch() | fetch() |
Azure Functions | N/A | fetch() | Isomorphic Unfetch / Cross-fetch | fetch() | fetch() |
AWS Lambda | N/A | fetch() | Isomorphic Unfetch / Cross-fetch | fetch() | fetch() |
Netlify Functions (AWS Lambda) | N/A | fetch() | Isomorphic Unfetch / Cross-fetch | fetch() | fetch() |
Web Assembly | TODO | TODO | TODO | TODO | TODO |
Some open points need to be clarified (Eventually, you can answer them?):
- Deno for Cloudflare Workers: I saw this guide, but I'm not sure if I can force Workers to run Deno under the hood. Both are JS runtimes, so makes not really sense to me. But eventually, it's more like a "pre-transformation"?
- Web Assembly: I know that you can import the I/O from the parent instance - in that case, fetch() should work, but I'm not 100% sure.
I marked Isomorphic Unfetch & Cross-fetch orange because neither seems the perfect solution. These are the suggested isomorphic libraries by node-fetch but:
Both implement a polyfill
of fetch()
to be consistent between Node
and WebAPI
. The polyfill
is a subset from fetch()
. Isomorphic Unfetch
is actively developed but has yet to support streaming. Unfetch | Github
Cross-Fetch
, on the other side, supports the WHATWG polyfill that is already more mature developed. But Cross-Fetch
is not anymore developed since one year back. Including missing support for Cloudflare Workers. It's a patch available, but to apply it, you need to fork Cross-Fetch
and maintain it yourself.
The question is, how impactful do you rate these points? Especially considering that Node 14 has EOL April this year and Node 16 has EOL September this year.
I expect to create a pull request during the upcoming week. To track our progress here:
- Replace Axios with Fetch
- Rewrite Tests to work with Fetch
- Test Isomorphix Unfetch
- Test Cross-Fetch
@mmailaender Thanks for the awesome writeup!
We are indeed killing axios and need to fill it in with an API that will work for web and Node. We also need to support HTTP2 for efficient connection management and to lay the foundation for server events (i.e. Event Streaming).
Cross-fetch is great, but has problems with platform support like you said (plus no HTTP2).
Node 18 has experimental support for the fetch
API. We could use that, but then we couldn't support the current LTS Node version at GA.
We are working on a test suite to make sure our solution is in fact compatible with various platforms. Hopefully we can point this issue at some PRs soon ๐ ๐
This was shipped in #66