How can I add a dynamic value to the request header? #5019
Unanswered
slamdunkYYY
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I currently use GraphQL with RTK Query, and the type is generated via
@graphql-codegen/typescript-rtk-query
as your suggestion. So that means the api has been injected in the generated file.Here is my api base setup.
Then the auto generated file is like:
Now, I want to add a dynamic value
api-trigger-location
to the request header. Initially, I want to modify it inonQueryStarted
and pass theapiTriggerLocation
via the request arg, based on this:https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-rtk-query#extending-generated-code
However, since the
apiTriggerLocation
is for the header only, it's not on the GQL schema, so cannot pass the TS check.So I create a wrapper to use
useEffect
to set the header:But this way will add the
api-trigger-location
to all GraphQL request, not only theapiEndpointTest
query. I cannot useprepareHeaders
increateApi
either since this is a dynamic value, it should pass from an argument.Could you please give me some suggestions?
Beta Was this translation helpful? Give feedback.
All reactions