ChilliCream / graphql-workshop

Getting started with GraphQL on ASP.NET Core and Hot Chocolate - Workshop
465 stars 199 forks source link

Subscription is closed with the error "Value cannot be null. (Parameter 'payload')" when need to return null #110

Closed kazakevich-alexei closed 1 month ago

kazakevich-alexei commented 11 months ago

EROR always when need return null.

Calling await sender.SendAsync($"CaseInProgress_{runId}", (int?)null);

public class CaseInProgressChangedPayload
  {
    public int? CaseInProgress { get; set; }
  }

  [Subscribe]
  [Topic("CaseInProgress_{runId}")]
  public CaseInProgressChangedPayload OnCaseInProgressChanged(int runId, [EventMessage] int? caseInProgress)
  {
    return new CaseInProgressChangedPayload
    {
      CaseInProgress = caseInProgress
    };
  }

OR
[Subscribe]
  [Topic("CaseInProgress_{runId}")]
  public int? OnCaseInProgressChanged(int runId, [EventMessage] int? caseInProgress) => caseInProgress;

OR
[Subscribe]
  [Topic("CaseInProgress_{runId}")]
  public int? OnCaseInProgressChanged(int runId, [EventMessage] int? caseInProgress)
  {
    return caseInProgress;
  }

Full log: {"type":"connection_ack"} { "id": "91f6db40-c442-45d3-b0d3-bf792ed379ee", "type": "error", "payload": [ { "message": "Value cannot be null. (Parameter 'payload')", "extensions": { "message": "Value cannot be null. (Parameter 'payload')", "stackTrace": " at HotChocolate.Execution.Instrumentation.SubscriptionEventContext..ctor(ISubscription subscription, Object payload)\r\n at HotChocolate.Execution.Processing.SubscriptionExecutor.Subscription.OnEvent(Object payload)\r\n at HotChocolate.Execution.Processing.SubscriptionExecutor.SubscriptionEnumerator.MoveNextAsync()\r\n at HotChocolate.AspNetCore.Subscriptions.OperationSession.SendResultsAsync(GraphQLRequest request, CancellationToken cancellationToken)\r\n at HotChocolate.AspNetCore.Subscriptions.OperationSession.SendResultsAsync(GraphQLRequest request, CancellationToken cancellationToken)\r\n at HotChocolate.AspNetCore.Subscriptions.OperationSession.SendResultsAsync(GraphQLRequest request, CancellationToken cancellationToken)" } } ] }

kevin-mcmanus commented 10 months ago

Following as I've just hit the same error. In my case, I return a custom record rather than an int?. The record itself is not null, but one of its properties is.

kevin-mcmanus commented 9 months ago

Looks like this is a duplicate of https://github.com/ChilliCream/graphql-platform/issues/6720