jasonkuhrt / graphql-request

Minimal GraphQL client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for NextJS revalidate/tags directly from request

opened this issue · comments

Perceived Problem

There is no option to pass next revalidate/tags when performing a request inside component

Ideas / Proposed Solution(s)

Something like this would be usefull:
client.request(GetMenusQuery, { ...vars }, { headers: {}, next: { revalidate: 60, tags: ['menu'] })

Docs https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-fetch.

Does anyone know if fetch being passed a request object supports this extended API? Did some code searches on GitHub but didn't immediately find where it is defined.

In general this should be possible with the new extension system. If it is not, I would like to know why, e.g. is it because the call to fetch must be changed (Nextjs options passed as second parameter to it).

graffle.extend(async ({ exchange }) => {
    exchange.input.request.next = { revalidate: 60, tags: [`menu`] }
    return exchange()
  }).document({
    foo: { query: { id: true } },
    bar: { query: { idNonNull: true } },
  })

In this case I am mutating instead of spreading the Request object to create a copy. I have some doubts about that.