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-queryas 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-locationto the request header. Initially, I want to modify it inonQueryStartedand pass theapiTriggerLocationvia the request arg, based on this:https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-rtk-query#extending-generated-code
However, since the
apiTriggerLocationis for the header only, it's not on the GQL schema, so cannot pass the TS check.So I create a wrapper to use
useEffectto set the header:But this way will add the
api-trigger-locationto all GraphQL request, not only theapiEndpointTestquery. I cannot useprepareHeadersincreateApieither 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