Reputation: 21
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.
Upvotes: 0
Views: 2042
Reputation: 128
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
Upvotes: 1
Reputation: 21
The question topic error message only shows up in GraphiQL
TL;DR: I resolved this issue by using a .Net Core 3.0 Console Application, instead of a ASP.NET Web Application Project Type.
Even though GraphiQL is the only editor which returns the above message, the problem remains regardless of how you try to consume the subscription. It just lacks an error message in other editors.
There must be some sort of background configuration I am not aware of (I am fairly new to C#/.NET). I was running the example star wars project files in a .NET Core Console Application, and an ASP.NET Web Application. They had the same files, correct name spacing, successful build, mutations and queries working in both projects.
But only the console project allows subscriptions.
I don't truly know how to resolve this issue except to start your root project as a .NET Core 3.0 Console Application, should someone else know I would love to have a better understanding of what this issue really is.
Upvotes: 0