Comments (13)
just a small note. Cloudflare doesn't implement AbortController which we need to terminate requests as well as streams. so it better to pass customized fetch. for example:
const client = new faunadb.Client({
'secret': 'your secret',
fetch: (url, params) => {
const signal = params.signal
delete params.signal
const abortPromise = new Promise(resolve => {
if(signal) {
signal.onabort = resolve
}
})
return Promise.race([abortPromise, fetch(url, params)])
}
})
from faunadb-js.
Is there any reason cross-fetch
doesn't just use the global fetch
when it exists?
from faunadb-js.
just a small note. Cloudflare doesn't implement AbortController which we need to terminate requests as well as streams. so it better to pass customized fetch. for example:
const client = new faunadb.Client({ 'secret': 'your secret', fetch: (url, params) => { const signal = params.signal delete params.signal const abortPromise = new Promise(resolve => { if(signal) { signal.onabort = resolve } }) return Promise.race([abortPromise, fetch(url, params)]) } })
this one actually works :O) previous solution fetch.bind(globalThis) Isn't work with fauna v4.x.x
from faunadb-js.
Hi @lolcoolkat thanks for the fix.
-
We used
cross-fetch
because some environments was having compatibility issues. So we need to find another solution instead of just remove it. -
I have to check what it is doing.
from faunadb-js.
@lolcoolkat NodeJS does not support fetch()
natively so we need to use some polyfill like cross-fetch
to make driver works on both environments (browser and nodejs). Unfortunately, we didn't find out a polyfill that was not using XMLHttpRequest however we are brainstorming to see what we can do about this issue so please, let us know if you have any ideas on your mind.
from faunadb-js.
@BrunoQuaresma We use Axios in the browser and on our node backend. Have you considered using that?
from faunadb-js.
@eigilsagafos I think axios uses XMLHttpRequests right?
from faunadb-js.
Yeah... you are right. Was just looking at that.
from faunadb-js.
I know some packages build for different environments and allow you to require like require("fauna/browser")
and require("fauna/node")
. Maybe you could even provide a barebones version where you could provide your own http adapter?
from faunadb-js.
Yeah, we are thinking on this solution as well but it adds some extra effort to define a common API interface that should work for these environments. Sounds strange to me a serverless environment does not support core NodeJS stuff. 🤔
from faunadb-js.
Yeah Cloudflare Workers run ontop of V8 and without all the NodeJS overhead.. that's why they are super quick and performant!
Cool, that makes sense.
Doesn't have to be exactly like that, but hopefully you get the idea :D And that config would allow you to specify whether to use cross-fetch or not?
I think it is a nice suggestion. We will evaluate that. Thanks for the contribution @lolcoolkat
from faunadb-js.
@lolcoolkat yes it is! We just need to add some tests and an extra environment in our pipeline to check things on V8 environments. Thanks for the suggestion.
from faunadb-js.
Fixes on https://www.npmjs.com/package/faunadb/v/2.11.2-beta. We are releasing this soon on the main version.
from faunadb-js.
Related Issues (20)
- provide internal function to "normalize" "data" result
- Property 'requestResult' does not exist on type 'typeof FaunaHTTPError'.
- invalid argument: Regular Class Ref expected, Schema Class Ref provided. HOT 3
- "invalid ref" when using `client.query( Create( Collection('test') ...` HOT 3
- UDF's not showing javascript variables HOT 2
- process.version & process.versions fail build on Vercel Edge API Route HOT 3
- Failing Queries from Cancelled Stream Error HOT 5
- The package "http2" wasn't found on the file system but is built into node HOT 11
- Typechecking functions such as `IsString` should also null as a parameter (typescript typing issue) HOT 2
- 4.7.0 to 4.7.1 causes InvalidValue error when importing code HOT 5
- TypeError: faunadb.Client is not a constructor HOT 10
- Is it safe to expose the key in the browser? HOT 3
- Explictly set 'Content-Type': 'application/json' HOT 1
- OPTIONS xhr request before POST HOT 1
- PageHelper.nextPage() fails to handle the final page HOT 2
- PageHelper.nextPage() throws an error if `size` parameter is passed to `Client.paginate()` HOT 1
- what is the status of the ESM driver? HOT 2
- require('util') fails in some ESM configurations HOT 1
- "TypeError: Incorrect type for the 'signal' field on 'RequestInitializerDict': the provided value is not of type 'AbortSignal'." HOT 1
- Allow login, disable creating account HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faunadb-js.