Skip to content

TanStack Query: need last-modified from response header #2070

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

Open
topical opened this issue May 23, 2025 · 2 comments
Open

TanStack Query: need last-modified from response header #2070

topical opened this issue May 23, 2025 · 2 comments
Labels
feature 🚀 New feature or request

Comments

@topical
Copy link

topical commented May 23, 2025

Description

Hi,

I use the TanStack Query code generator and need access to response header.

In my scenario, REST-API requires 'If-Unmodified-Since' header to be passed to properly handle concurrent updates.

For this, I need to extract 'last-modified' from response headers. Actually, this looks like being almost impossible with code generated by HeyAPI.

E.g. I have an endpoint to retrieve information about a user. HeyAPI generates the following code for this:

export const getUserQueryQueryKey = (options?: OptionsLegacyParser<GetUserQueryData>) => [
  createQueryKey('getUserQuery', options),
]

export const getUserQueryOptions = (options?: OptionsLegacyParser<GetUserQueryData>) => {
  return queryOptions({
    queryFn: async ({ queryKey, signal }) => {
      // watch out: response header is discarded here!
      const { data } = await getUserQuery({
        ...options,
        ...queryKey[0],
        signal,
        throwOnError: true,
      })
      return data
    },
    queryKey: getUserQueryQueryKey(options),
  })
}

You see that the response header is discarded deeply inside.

Effectively, I have to rewrite getUserQueryQueryKey() and getUserQueryOptions(). That's kind of OK for a single API-endpoint, but not suitable for my application.

So: is there any idea to handle this more generic?

Thank you!

@topical topical added the feature 🚀 New feature or request label May 23, 2025
@MeCapron
Copy link

Hello,

I'm running into the same exact issue to extract the filename of a downloaded file using responseType blob!

@mrlubos
Copy link
Member

mrlubos commented May 31, 2025

@topical @MeCapron would you want to modify the response from TanStack query so that data becomes data.data and there'd be a new field data.headers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants