Supporting url in ClientOptions to be a function that returns a Promise #145
edwardfeng-db
started this conversation in
General
Replies: 1 comment 3 replies
-
Hi there, before we begin, this request belongs to Issues, not Discussions. Simply because it is an enhancement and you can close the Issue with a PR using the Nevertheless, I like the idea! Good thinking. 😄 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, currently we have a use case that there is service that's checking csrf token upon the initial request, and it's expecting the csrf token to be part of the query string (url in this context). Basically we are trying to make the url follow this pattern
wss://graphql-ws?csrf=<token>
.The csrf token could expire, so when there's an invalid token error, we would like to refetch and recreate a
graphql-ws
client with the updated token. Therefore, to make it recreate the client using the updated token, we would like to makeurl
to support a function type that returns a Promise, so it can be dynamically updatable.Specifically, we'd like our use case to be like this:
createClient({ url: () => new Promise((resolve) => { resolve(getUrlWithLatestCsrfToken()) }), lazy: true, })
I made a PR here such that the url now has type
string | (() => Promise<string> | string)
, which is similar toconnectionParams
. @enisdenjo Can you let me know your thought on this?Beta Was this translation helpful? Give feedback.
All reactions