graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Subscription not getting data even after client succesfully connects

Open SaranSundar opened this issue 3 years ago • 6 comments
trafficstars

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)
    {
    }`
Screen Shot 2022-05-12 at 11 08 03 PM

SaranSundar avatar May 13 '22 04:05 SaranSundar

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

Alfieri avatar May 17 '22 08:05 Alfieri

@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 avatar May 17 '22 13:05 rose-a

@rose-a That didn't work for me unfortunately.

SaranSundar avatar May 18 '22 22:05 SaranSundar

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

SaranSundar avatar May 18 '22 23:05 SaranSundar

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.

rose-a avatar May 19 '22 06:05 rose-a

The server uses netflix dgs which does seem to use graphql-ws for the websocket connection

SaranSundar avatar May 20 '22 05:05 SaranSundar