Make WebsocketLink headers work the same as AuthLink#123
Make WebsocketLink headers work the same as AuthLink#123darahayes merged 3 commits intoaerogear:masterfrom fermuch:patch-1
Conversation
Before this change, the function was returning an object of the type `{ Authorization: any }`, which is incompatible with what is expected from `connectionParams`. This change uses the same methods as they are used on AuthLink.
|
ping @darahayes |
|
Thank you so much for contribution. I will check why tests are failing and merge this PR as soon as possible |
|
Thanks @wtrocki ! May I add the question: where is |
|
Hey @fermuch I've done a little bit of work around the WebsocketLink and the AuthContextProvider. To answer your question about |
Are you sure this is definitely incompatible with what is expected from Documentation for export type ConnectionParams = {
[paramName: string]: any,
};My understanding is this, the original code is definitely making some bad assumptions but I think we also do not need to explicitly return an object with the I think instead we should refactor the AuthContext interface to look something like this: export interface AuthContext {
headers: {
[headerName: string]: any
}
}Here we would rename And then in the the WebsocketLink we would have: connectionParams: async () => {
if (userOptions.authContextProvider) {
const { headers } = await userOptions.authContextProvider();
return headers
}
},and then the AuthLink would become: export const createAuthLink = (config: OffixClientConfig): ApolloLink => {
const asyncHeadersLink = setContext(async (operation, previousContext) => {
if (config.authContextProvider) {
const { headers } = await config.authContextProvider();
return {
headers
};
}
});
return asyncHeadersLink;
};@fermuch can you try out that code and see if it works for you and if it does, then we would be really happy to accept those changes. |
|
@darahayes Let's make suggested changes on top of this PR and we can integrate it for this release.
Let's do it as we going to have now breaking release so no worries with introducting this change. Big +1 on any cleanup from our side |
connectionParams accept
I completly agree!
Got it! |
I agree we shouldn't explicitly have I'm also +1 to the breaking change because we're putting out a release with breaking changes soon. |
|
I've applied the changes proposed by @darahayes and tested locally on my app. |
|
Awesome, thanks so much @fermuch! |
Description
Before this change, the function was returning an object of the type
{ Authorization: any }, which is incompatible with what is expected fromconnectionParams. This change uses the same methods as they are used on AuthLink.Tests are not passing but it seems to be unrelated to this change (errors come from
CacheHelpersTest.ts)Checklist
npm testpassesnpm run buildworks