nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

useGqlHeaders and useGqlToken aren't reactive

Open TheDutchCoder opened this issue 3 years ago • 3 comments

When using useGqlHeaders or useGqlToken, I would assume that the passed values can be refs and that the headers/tokens would update on subsequent requests if the refs change.

A simple use-case is sending along JWT access-tokens that change after each GraphQL call.

Currently it will use just use the initial passed in value.

TheDutchCoder avatar Sep 07 '22 15:09 TheDutchCoder

Currently it will use just use the initial passed in value.

Indeed.

Allowing reactive values to be passed and updated accordingly would certainly be a welcomed improvement, I had initially avoided that very implementation to reduce unintended side effects and ultimately make the debugging process easier on developers' ( having to explicitly call the functions when you wish to affect the underlying request )

Diizzayy avatar Sep 07 '22 15:09 Diizzayy

Yeah I understand it from a simplicity POV! The hard part is that if you have to trap every call to Graph, it becomes a bit unwieldy.

I know JWT accessToken/refreshToken is in the pipeline, but I also know you worked on some nuxt3 apollo-client things which might be easier to use.

Normally you'd use an apollo link to read out response headers, store the new accessToken and sent it along on the next request, which is what I'm trying to achieve here.

TheDutchCoder avatar Sep 07 '22 15:09 TheDutchCoder

Hey @Diizzayy I am having issue with the 'Currently it will use just use the initial passed in value' mentioned above. I have implemented a basic JWT refresh token middleware but when I attempt to clear out the headers via useGqlHeaders or useGqlToken the are sent anyway.

Accepting reactive values would be a great enhancement but could you allow static values to work if updated in a middleware?

sweetroll avatar Sep 12 '22 08:09 sweetroll