-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Description
Hi!
I've used patch-package to patch [email protected]
for the project I'm working on.
I found that the graphql_headers
were not being passed down during the realtime handshake initialization. I needed a custom header in the Auth Lambda but I wasn't receiving it in the requestHeaders
from the event
object. After debugging, I found this line where the _initializeWebSocketConnection
does the handshake:
Line 399 in ea05577
graphql_headers: () => { } |
Here is the diff that solved my problem:
diff --git a/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js b/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
index 612efd0..c8c669d 100644
--- a/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
+++ b/node_modules/aws-appsync-subscription-link/lib/realtime-subscription-handshake-link.js
@@ -318,7 +318,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
authenticationType: authenticationType,
region: region,
credentials: credentials,
- token: token
+ token: token,
+ graphql_headers: graphql_headers
})];
case 3:
_g.sent();
@@ -362,7 +363,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
};
AppSyncRealTimeSubscriptionHandshakeLink.prototype._initializeWebSocketConnection = function (_a) {
var _this = this;
- var appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, authenticationType = _a.authenticationType, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token;
+ var appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, authenticationType = _a.authenticationType, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token, graphql_headers = _a.graphql_headers;
if (this.socketStatus === types_1.SOCKET_STATUS.READY) {
return;
}
@@ -388,7 +389,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
region: region,
credentials: credentials,
token: token,
- graphql_headers: function () { }
+ graphql_headers: graphql_headers
})];
case 2:
headerString = _b.apply(_a, [_c.sent()]);
Now it works using setContext
from Apollo:
const customHeadersMiddleware = setContext((_, { headers }) => {
return {
headers: {
...headers,
'x-custom-header': 'my-value',
},
};
});
const subscriptionLink = ApolloLink.from([
customHeadersMiddleware,
createAuthLink(subscriptionLinkParams),
createSubscriptionHandshakeLink(subscriptionLinkParams),
]);
This should solve #630 #761 and maybe #585
This issue body was partially generated by patch-package.
JairoQuispe
Metadata
Metadata
Assignees
Labels
No labels