Detect and handle when StrawberryShake Subscription connection wasn't successful

438 views Asked by At

I have two asp.net applications running locally in development mode. One is running HotChocolate as the GraphQL server and working well. The second application is attempting to run StrawberryShake GraphQL client and access a subscription.

The StrawberyShake documentation is pretty sparse, especially with subscriptions and I'm unable to figure out how to know when a connection error happens. I've pasted below the code that shows what I've tried so far with no success. I've added comments to show what doesn't happen.

            try
            {
                // client is the client auto-generated by StrawberryShake.
                session = client.KeyRequest
                    .Watch(new ServerInfoInput
                    {
                        Name = "test",
                        MachineIdentifier = "machine",
                    }).Subscribe(result =>
                    {
                        // A breakpoint in here never gets hit.
                        var data = result.Data;
                    }, () =>
                    {
                        // This writeline never gets hit.
                        Console.WriteLine("Complete");
                    });
            }
            catch (Exception e)
            {
                // An exception is never thrown.
                Console.WriteLine(e.ToString());
            }

In conclusion, is there a way to know if my connection to the server was successful?

1

There are 1 answers

0
fhewitt On

Short answer: no.

Strawberry has a stale issue from 2021 about this: https://github.com/ChilliCream/graphql-platform/issues/4184

On the thread you can find workarounds from CoreDX9 and horego, but they seem outdated and don't works as is. The idea is to monitor the socket yourself using interceptor or reflexion.