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

Feature: support custom fetch functions #251

Open
2 tasks done
Sandros94 opened this issue Apr 30, 2024 · 4 comments
Open
2 tasks done

Feature: support custom fetch functions #251

Sandros94 opened this issue Apr 30, 2024 · 4 comments

Comments

@Sandros94
Copy link

Is your feature request related to a problem?

Ability to override what fetch to use when using this SDK.

Also noticed that this was possible in 0.11.

Describe the solution

Most frameworks do have a custom fetch built-in.
This make sure that the fetch function works in all the production environment supported by the framework itself, with the added ability to customize other logics (eg.: logging framework side).

When defining a new Surreal to be able to override the http fetch function, with something like ofetch:

import { Surreal } from 'surrealdb.js';
import { ofetch } from 'ofetch';

const db = new Surreal({
  fetch: ofetch.create({
    onRequestError: ({ request, options, error }) => {
      if (import.meta.dev) {
        console.error('Request error:', request, options, error)
      }
    },
    onResponseError: ({ request, options, response, error }) => {
      if (import.meta.dev) {
        console.error('Response error:', request, options, response, error)
      }
    }
  })
});

Alternative methods

Dropping the use of the SDK and reimplement its functionality using framework's native functions. But its just duplicate work.

SurrealDB version

1.4.2 for windows on x86_64

SurrealDB.js version

1.0.0-beta.5

Contact Details

sandro.circi@digitoolmedia.com

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kearfy
Copy link
Member

kearfy commented May 6, 2024

Hiya @Sandros94, we have intentionally chosen to drop support for custom fetch functions as affects the integrity of the code and can cause unexpected issues. From NodeJS v20 onwards, all major runtimes and platforms support fetch natively. As the version 1 of this library is still in beta, this is not yet documented, however once we stabilize the version we will make sure to document this requirement

@kearfy kearfy closed this as completed May 6, 2024
@Sandros94
Copy link
Author

Ehy @kearfy, objectively speaking and I hope not to sound like the drama guy:

This is the Javascript driver repo and not the NodeJS driver repo. Is the node driver going to be deprecated?

Custom fetch do more than just be platform agnostic.
Depending on the implementation, for example, they also let you define different network connection and configuration based on where the event is executed (client or server side). While bigger platforms like Vercel, AWS, Cloudflare tend to be as much compatible as possible, they often use additional configurations for things like worker to worker communication to prevent public network requests.

Now, instead, my personal opinion:
when I build a new module for Nuxt ecosystem I want to make it as easy to debug as possible. Nowdays, it is becoming harder and harder to debug what people are facing when they come by and open up an issue in your repository. So, to help my future-self as much as possible I tend to enable any possible logging during development (taking advantage of onRequest, onResponse, onRequestError and onResponseError functions within a custom fetch), something that most framework are able to. By removing these type of customizations, in a general purpose driver like the JS one, it would make life harder for framework-specific drivers. The result is always a full driver rewrite, duplicated work, project frammentation and pointing fingers when edge cases do inevitably rise.

@kearfy
Copy link
Member

kearfy commented May 6, 2024

Thanks for your thoughts @Sandros94, I'll take it into consideration and discuss it with the team!

@kearfy kearfy reopened this May 6, 2024
@Sandros94
Copy link
Author

Thanks for your thoughts @Sandros94, I'll take it into consideration and discuss it with the team!

I'm happy to share them! Feel free to ping me here or on discord

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

2 participants