-
Notifications
You must be signed in to change notification settings - Fork 135
Could not connect with AWS graphQL client (Appsync APIs) #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I managed to get it working with Appsync but only for SendQueryAsync calls. I've also not had much luck yet in getting the websocket connection for realtime subscriptions. |
Anyone figure this out? I too can query without an issue but get the following error when trying to connect with websockets. The server returned status code '401' when status code '101' was expected. |
AppSync seems to use a different endpoint for websocket connections, see here. You need to create a second instance of |
Sorry, I am trying to use the client in csharp and changing the url to wss does not work. I do this; clientWebsockets = new GraphQLHttpClient("wss://host/graphql", new NewtonsoftJsonSerializer());
clientWebsockets.HttpClient.DefaultRequestHeaders.Add("x-api-key", clientApiKey);
clientWebsockets.HttpClient.DefaultRequestHeaders.Add("host", host);
var onUpdateNotificationReq = new GraphQLRequest
{
Query = @"
subscription {
onUpdateNotification {
id
name
action
}
}"
};
IObservable<GraphQLResponse<UserJoinedSubscriptionResult>> subOnUpdateNotificationStream = clientWebsockets.CreateSubscriptionStream<NotificationOnUpdateSubscriptionResult>(onUpdateNotificationReq, (ex) =>
{
// ERROR HERE
Log("EX: " + ex.Message + Environment.NewLine);
});
subOnUpdateNotification = subOnUpdateNotificationStream.Subscribe(response =>
{
Log("NEVER SHOWS UP");
}); end up with same error - The server returned status code '401' when status code '101' was expected. |
The header must be sent as url query parameter as described here: https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html. The example there is
|
Are you telling me that I need to create my own websocket requests and cannot use your system for subscriptions? I do not get the error anymore with the below code, but I never see any data. var headersWs = new Dictionary<string, string>() {
{ "host", clientHost },
{ "x-api-key", clientApiKey }
};
var sHeadersWs = JsonConvert.SerializeObject(headersWs);
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(sHeadersWs);
var x = System.Convert.ToBase64String(plainTextBytes);
var uri = clientEndpointWs + "?header=" + x + "&payload=e30=";
clientWs = new GraphQLHttpClient(uri, new NewtonsoftJsonSerializer());
await clientWs.InitializeWebsocketConnection();
var req = new GraphQLHttpRequest
{
Query = @"
subscription OnUpdateNotification {
onUpdateNotification {
id
name
action
createdAt
updatedAt
}
}",
OperationName = "OnUpdateNotification",
};
subscriptionStream = clientWs.CreateSubscriptionStream<NotificationOnUpdateSubscriptionResult>(req);
sub = subscriptionStream.Subscribe(response =>
{
Log("Here");
Log(response.Data.onUpdateNotification.Name);
}); |
Nope, I didn't tell you anything like that. Please post your |
public class NotificationType
{
public string Id { get; set; }
public string Name { get; set; }
public string Action { get; set; }
}
public class NotificationOnUpdateSubscriptionResult
{
public NotificationType onUpdateNotification { get; set; }
}
sub = subscriptionStream.Subscribe(response =>
{
Log("Here");
Log(response.Data.onUpdateNotification.Name);
}, error =>
{
Log("ERROR");
Log(error.Message);
}); I never get a response, not even an error. Note that when I used an incorrect URI I would get the 401 error so I think the URI is not connecting, but not sure as there are no messages. Thanks for all your help so far! |
Looks ok to me. Did you try to create a subscription using a different tool (like Altair)? Does this work? Please post the subscription query string and response from there... |
I tested with Altair and do not receive any error message nor any data. Thank you for your help but it seems connecting to AppSync is not something via C# is not going to work so I am moving to another code base |
Altair is a JavaScript app... I'm sorry, but it seems something else is wrong there. But go ahead. |
There are a couple of showstopper issues. I have fixes for them locally but have not yet polished them for a pull-request. Issue 1 - Set explicit endpoint for WebSocketThe var header = new AppSyncHeader {
Host = "abcedef.appsync-api.us-west-2.amazonaws.com",
ApiKey = "abcdef"
};
_graphQlClient.Options.WebSocketEndPoint = new Uri($"wss://abcedef.appsync-realtime-api.us-west-2.amazonaws.com/graphql"
+ $"?header={Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(header)))}"
+ "&payload=e30="
); With class AppSyncHeader {
//--- Properties ---
[JsonPropertyName("host")]
public string Host { get; set; }
[JsonPropertyName("x-api-key")]
public string ApiKey { get; set; }
} Issue 2 -
|
I spoke a bit too soon. Some more changes were needed. I opened a draft pull-request: #287 I also created a sample Blazor WebAssembly app to show how it works: https://github.com/bjorg/GraphQlAppSyncTest/blob/main/MyApp/Pages/Index.razor |
Hello @symposiumjim ! Thank you! |
I am trying to implement the same example given below in python with .net and this grahQL-client nuget but I am always getting error that the "server closed the connection without a closing handshake".
https://aws.amazon.com/blogs/mobile/appsync-websockets-python/
The code in above sample is working good in python.
could any please help with this. I am trying to fix from last two week. Not sure its something inside the library or I am not able to use the library correctly.
My code looks like
The text was updated successfully, but these errors were encountered: