graphql-client
graphql-client copied to clipboard
Subscription not getting data even after client succesfully connects
Hello,
I'm using Spring Boot Netflix DGS as my graph server, trying to connect with C# as a client for a subscription
While looking through the other issues posted on here ive pieced this together, this is a basic new c# console app, so im just keeping while true to stop the app from exiting after subscribing to the subscription. I can see on my java server the log message client connected, but I don't get any data back from the subscription. I can confirm the subscription works with other tools like apollo playground. I'm not geting any error, just not geting any data back.
Java server code
@DgsSubscription public Publisher<GameState> gameStates() { log.info("Client connected"); return gameService.getGameStatePublisher(); }
C# Code
` var gameStateSubscriptionRequest = new GraphQLRequest
{
Query = @"
subscription{
gameStates{
id
}
}"
};
// Create JsonSerializer
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver { IgnoreIsSpecifiedMembers = true },
MissingMemberHandling = MissingMemberHandling.Ignore
};
serializerSettings.Converters.Add(new ConstantCaseEnumWorkaroundConverter());
// See https://github.com/graphql-dotnet/graphql-client/issues/311
var jsonSerializer = new NewtonsoftJsonSerializer(serializerSettings);
// Establish Client
var _subscriptionClient = new GraphQLHttpClient(o =>
{
o.WebSocketEndPoint = new Uri("ws://localhost:8080/subscriptions");
o.UseWebSocketForQueriesAndMutations = false;
},
jsonSerializer);
var subscriptionStream = _subscriptionClient.CreateSubscriptionStream<dynamic>(gameStateSubscriptionRequest);
var subscription = subscriptionStream.Subscribe(response =>
{
Console.WriteLine("Data is");
Console.WriteLine(response.Data);
});
while (true)
{
}`
Thanks for raising the issue. I also notice the same behavior today.
I'm using the following Versions:
- latest GraphQL Client version 4.0.2
- Graphql.Server.Transport.AspNetCore v5.2.0
- Graphql package v4.7.1
@SaranSundar Please try specifying a proper return type istead of dynamic. You can either create a class for that or use the extension methods which let you declare an anonymous return type:
var subscriptionStream = _subscriptionClient.CreateSubscriptionStream(gameStateSubscriptionRequest, () => new { gameStates = new { id = string.Empty }});
var subscription = subscriptionStream.Subscribe(response =>
{
Console.WriteLine("GameStates id is");
Console.WriteLine(response.Data.gameStates.id);
});
@rose-a That didn't work for me unfortunately.
Is it possible its related to this
https://github.com/Netflix/dgs-framework/issues/1036
Does the graphql client in c# expect only certain fields and will fail if extra fields were passed into the subscription response from the server
Does the graphql client in c# expect only certain fields and will fail if extra fields were passed into the subscription response from the server
It should ignore the dataPresent field, the extensions field is supported and deserialized into a Dictionary<string,object>.
Which websocket subprotocol does your server use? This library currently only supports graphql-ws.
The server uses netflix dgs which does seem to use graphql-ws for the websocket connection