Giter Club home page Giter Club logo

Comments (13)

fireridlle avatar fireridlle commented on September 1, 2024 10

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.

Ayplow avatar Ayplow commented on September 1, 2024 3

Is there any reason cross-fetch doesn't just use the global fetch when it exists?

from faunadb-js.

Mhmdrza avatar Mhmdrza commented on September 1, 2024 1

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.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

Hi @lolcoolkat thanks for the fix.

  1. We used cross-fetch because some environments was having compatibility issues. So we need to find another solution instead of just remove it.

  2. I have to check what it is doing.

from faunadb-js.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

@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.

eigilsagafos avatar eigilsagafos commented on September 1, 2024

@BrunoQuaresma We use Axios in the browser and on our node backend. Have you considered using that?

from faunadb-js.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

@eigilsagafos I think axios uses XMLHttpRequests right?

from faunadb-js.

eigilsagafos avatar eigilsagafos commented on September 1, 2024

Yeah... you are right. Was just looking at that.

from faunadb-js.

eigilsagafos avatar eigilsagafos commented on September 1, 2024

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.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

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.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

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.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

@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.

BrunoQuaresma avatar BrunoQuaresma commented on September 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.