graphql-dotnet / graphql-dotnet/graphql-client
Trouble getting CreateSubscriptionStream to work
- Dominant language
- C#
- Stars
- 648
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Trying to follow the documentation to get subscriptions to work. The documentation on the Readme doesn't mention InitializeWebsocketConnection, but I saw that in some of the other code linked in similar issues here. But when I run that, I get `WebSocketException : The server returned status code '400' when status code '101' was expected.`
Not sure how to configure this correctly. Something on the server side I'd need to do? I know the subscription code works ok.
```
[Fact]
public async Task TestIt()
{
var client = new GraphQLHttpClient("http://localhost:4000/graphql/", new NewtonsoftJsonSerializer());
await client.InitializeWebsocketConnection();
IObservable> observableStream = client.CreateSubscriptionStream(SubscriptionGQL.Request());
var observer = new GraphQlObserver();
using var subscription = observableStream.Subscribe(observer);
subscription.Dispose();
}
```
Observer def:
```
public class GraphQlObserver : IObserver>
{
private readonly List _ids;
public bool IsComplete { get; private set; }
public GraphQlObserver()
{
_ids = new List();
}
public void OnCompleted()
{
IsComplete = true;
}
public void OnError(Exception error)
{
throw new NotImplementedException();
}
public void OnNext(GraphQLResponse value)
{
_ids.AddRange(value.Data.streamDocumentIds);
}
}
```
GraphQLRequest
```
public class SubscriptionGQL
{
public static GraphQLRequest Request()
{
return new GraphQLRequest
{
Query = SubscriptionDocument,
OperationName = "Subscription"
};
}
public static string SubscriptionDocument = @"
subscription Subscription {
streamDocumentIds
}
";
}
```
Subscription class
```
public class Subscription
{
[JsonProperty("streamDocumentIds")]
public List streamDocumentIds { get; set; }
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.