Skip to content
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

Cloudflare Workers and global fetch??? #548

Open
danboyle8637 opened this issue Oct 17, 2021 · 3 comments
Open

Cloudflare Workers and global fetch??? #548

danboyle8637 opened this issue Oct 17, 2021 · 3 comments

Comments

@danboyle8637
Copy link

I have been trying to figure out a way to make this...

https://github.com/fauna/faunadb-js#known-issues

Work with Typescript. But I'm confused.

Cloudlfare Workers do have a native fetch so I'm confused as to why the workaround is needed.

I can't find anything about them supporting AbortController.... but maybe we can set a timeout and skill the Fauna Request or the stream. Although if it's a stream would you not kill that manually???

Can you help explain how Fauna uses cross-fetch more?

Maybe there is a way around this. Cloudflare Workers did just release Workers Unbound with 30 seconds of "alive" time.. not sure what you realy call that.

Anyway I would really love to get this working with TS support but I am at a standstill at the moment.

@github-actions
Copy link

Internal ticket number is OSS-958

@grempe
Copy link

grempe commented Dec 17, 2021

FYI The known issues section of the README that the OP referenced has apparently been removed in this commit by @parkhomenko :

6e386ec

It's not clear if anything else other than the doc removal has changed.

@dferber90
Copy link

dferber90 commented Jan 16, 2022

AbortController and AbortSignal are both supported now. It seems this is why the docs were removed and I believe this issue can be closed now.

https://community.cloudflare.com/t/2021-9-24-workers-runtime-release-notes/308821

Only for reference, no longer needed

This is how the workaround would have needed to be typed to work with TypeScript. But the workaround itself is no longer necessary now, so don't copy this into any new projects. You don't need to specify fetch anymore when creating a fauna client in a Cloudflare Worker.

new faunadb.Client({
  // ...
  fetch: (
    url: RequestInfo,
    params?: RequestInit | undefined
  ): Promise<Response> => {
    let signal: RequestInit["signal"];
    if (params) {
      signal = params.signal;
      delete params.signal;
    }
    const abortPromise = new Promise<Response>((resolve) => {
      if (signal) {
        // @ts-ignore
        signal.onabort = resolve;
      }
    });
    return Promise.race([abortPromise, patchedFetch(url, params)]);
  },
})

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

No branches or pull requests

3 participants