Search code examples
c#.netgraphqlgraphql-subscriptionshotchocolate

Hot Chocolate "RESULT_TYPE_NOT_SUPPORTED" on subscription


edit 00: NOTE: This message is coming from the GraphiQL interface. When I tried the same query in the 'Banana Cake Pop' UI, no message is returned when I execute this query.


While trying to create a GraphQL subscription on an ASP.NET web server, using Hot Chocolate, with exactly the same code found in this tutorial, I am receiving error feedback from the server.

Error Message

{
  "errors": [
    {
      "message": "Result type not supported.",
      "extensions": {
        "code": "RESULT_TYPE_NOT_SUPPORTED"
      }
    }
  ]
}

I have tried to recreate the tutorial exactly and it's not working. I am also unable to get any of the examples working from these examples. It's only with subscriptions though, queries and mutations are all working perfectly fine.

Services Configuration

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();

    // [GRAPHQL]
    services.AddInMemorySubscriptionProvider();

    services.AddGraphQL(SchemaBuilder.New()
        .AddQueryType<ShuttleQuery>()
        .AddMutationType<ShuttleMutation>()
        .AddType<Subscription>()
        .BindClrType<string, StringType>()
        .Create()
    );
}

Application Configuration

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }

    app.UseStaticFiles();

    app.UseHttpsRedirection();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
        endpoints.MapControllers();
    });


    // [GRAPHQL]
    app.UseWebSockets().UseGraphQL("/graphql");
    app.UseGraphQL("/graphql");
}

Generic subscription type based on the tutorial

public class Subscription
            
{
    [SubscribeAndResolve]
    public async IAsyncEnumerable<string> OnMessageAsync()
    {
        yield return "Hey!";
        await Task.Delay(2000);
        yield return "It Changed?";
        await Task.Delay(2500);
        yield return "It Never Changes Because It Doesn't W";
    }
}

I have been stuck on this for some days now, any help would be greatly appreciated.


Solution

  • I had the same error when try to call subscription from code(FE: react, BE: .net core). And probelm was that I call subscription via http... Subscription works via WebSocket. So check if you app call subscription wia WEbSocket. Here you can see how to configure client to split request between http and ws : https://github.com/howtographql/react-apollo/blob/master/src/index.js