Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Conversation

g12i
Copy link

@g12i g12i commented Mar 23, 2024

What kind of change does this PR introduce?

This adds a possibility to pass any fetch options (e.g. next options to fetch while building the query.

What is the current behavior?

Currently we can pass fetch at PostgrestBuilder creation. Which effectively means once, if using Supabase. One would have to parse URL and alter options depending on the URL. E.g. for passing next.tags options

  const postgrest2 = new PostgrestClient<Database>('http://localhost:3000', {
    fetch: (url, init) => {
      let parsedUrl: URL

      if (url instanceof URL) {
        parsedUrl = url
      } else if (typeof url === 'string') {
        parsedUrl = new URL(url)
      } else {
        parsedUrl = new URL(url.url)
      }

      const tags: string[] = []
      if (parsedUrl.pathname.startsWith('/rest')) {
        const [,, entity] = parsedUrl.pathname.split('/').slice(1)
        tags.push(entity)
      }

      return fetch(url, {
        ...init,
        next: {
          tags,
        },
      })
    },
  })

What is the new behavior?

Allow to pass fetchOptions options when building query. The idea here is

  const res = await postgrest
    .from('users')
    .select()
    .eq('username', 'supabot')
    .fetchOptions({
      next: { tags: ['users/supabot'] },
    })

// ... later in the code

revalidateTag('users/supabot');

Because FetchOptions include signal, it is marked as deprecated and uses .fetchOptions internally.

@bnjmnt4n
Copy link
Contributor

bnjmnt4n commented Apr 2, 2024

Instead of this being Next.js specific, not sure if it might be better to just allow customization of any fetch option?

@g12i
Copy link
Author

g12i commented Apr 2, 2024

Yeah, I agree @bnjmnt4n. Let me make a quick update

@g12i g12i changed the title Allow to pass Next.js options to fetch while building query Allow to pass fetch options while building query Apr 2, 2024
@g12i g12i changed the title Allow to pass fetch options while building query Allow to pass fetch options while building the query Apr 3, 2024
@g12i
Copy link
Author

g12i commented May 30, 2024

Hello @soedirgo, any chance this gets reviewed?

@toniab
Copy link

toniab commented Oct 7, 2024

@soedirgo bump :P

@aiddun
Copy link

aiddun commented Oct 31, 2024

Any update on this?

@mandarini
Copy link
Contributor

Hi @g12i ! Thank you very much for you meaningful contribution, and apologies for not reviewing it for such a long time.

This repository is deprecated and has moved to the new Supabase JS monorepo.

May I ask you, if you believe this change is still needed, please open a new PR in the monorepo and include a link back to this thread for context:

I will be closing this PR now, but you can always access it and view the changes, even after the repo is archived, don't worry!

@mandarini mandarini closed this Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants