Async connectionParams at request time
See original GitHub issueIssue
We supply the authentication token while the request is being made for the http case, this comes in the form of a Token
http header.
For the WS case, we wish to supply authentication information (preferably when we first subscribe to the subscription), this is because when the GraphQLWsLink is created, the user has not logged in yet and hence we have no token to supply.
Is there a way of doing some WS equivalent:
const authLink = new ApolloLink(async (operation, forward) => {
// Mint the token
const token = createToken();
// Use the setContext method to set the HTTP headers.
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : "",
},
});
// Call the next link in the middleware chain.
return forward(operation);
});
What we’re after is some way to do something like this:
const wsLink = new GraphQLWsLink(
createClient({
url: graphqWSlURL,
// Called sometime after we've had the chance to log the user in.
+ buildConnectionParams: () => {
+ // Mint the token
+ const token = createToken();
+ return {
+ authorization: token ? `Bearer ${token}` : "",
+ }
+ }
//The user isn't logged in yet
- connectionParams: {
- authorization: //we dont have the token yet :(
- },
})
);
Maybe there’s a way to do this that I don’t know about?
Issue Analytics
- State:
- Created a year ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
[FEATURE REQUEST] `connectionParams` accept async ...
I want to fetch authToken from local storage any time socket init. But i can't do it right now, because it dont accept...
Read more >Subscriptions in Apollo Server - Apollo GraphQL Docs
Those connectionParams are sent to your server when it connects, allowing you to extract information from the client request by accessing Context.
Read more >GraphQL Subscription Authentication Using AsyncStorage
Am trying to use subscription on my client app to send JWT Token and refreshToken to the server using WebSocketLink connectionParams.
Read more >Using Asyncio with Elasticsearch
import asyncio from elasticsearch import AsyncElasticsearch es ... timeout – Time each individual bulk request should wait for shards that are unavailable.
Read more >Subscriptions | NestJS - A progressive Node.js framework
GraphQL subscriptions are a way to push data from the server to the clients that choose to listen to real time messages from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like you can supply an async function, cheers!
strange, but the global typing says “no” in my ide, and when i try it, i get the error, that the method takes no parameter. But that’s none of your business.
Thanks again 😃