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

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

Open kazakevich-alexei opened this issue 2 years ago • 2 comments

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)" } } ] }

kazakevich-alexei avatar Nov 23 '23 23:11 kazakevich-alexei

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 avatar Dec 14 '23 12:12 kevin-mcmanus

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

kevin-mcmanus avatar Jan 02 '24 10:01 kevin-mcmanus