Skip to content

Add support for QueryContext with mutation conventions #8256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
glen-84 opened this issue Apr 21, 2025 · 1 comment
Open

Add support for QueryContext with mutation conventions #8256

glen-84 opened this issue Apr 21, 2025 · 1 comment

Comments

@glen-84
Copy link
Collaborator

glen-84 commented Apr 21, 2025

Product

Hot Chocolate

Is your feature request related to a problem?

// Mutation conventions enabled ...
public static async Task<User?> RegisterUser(
    RegisterUserInput input,
    QueryContext<User> query,
    IMediator mediator,
    CancellationToken cancellationToken)
{
    var (isSuccess, userId, errors) = await mediator.Send(
        new RegisterUserCommand(input.Username, input.EmailAddress),
        cancellationToken);

    return isSuccess
        ? await mediator.Send(new GetUserByIdQuery(userId, query), cancellationToken)
        : throw new AggregateException(errors.ToDomainExceptions());
}
  message: The selection set is empty.
  stackTrace: "   at
    HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildExpr\
    ession[TRoot](ISelection selection)\r

    \   at
    HotChocolate.Execution.Processing.HotChocolateExecutionSelectionExtensi\
    ons.<>c__2`1.<GetOrCreateExpression>b__2_0(String _, ValueTuple`2 ctx)\r

    \   at
    HotChocolate.Execution.Processing.Operation.GetOrAddState[TState,TConte\
    xt](String key, Func`3 createState, TContext context)\r

The solution you'd like

Add support for QueryContext with mutation conventions.

@glen-84
Copy link
Collaborator Author

glen-84 commented May 2, 2025

Workaround:

public static async Task<User?> RegisterUser(
    RegisterUserInput input,
    IResolverContext context,
    IMediator mediator,
    CancellationToken cancellationToken)
{
    var (isSuccess, userId, errors) = await mediator.Send(
        new RegisterUserCommand(input.Username, input.EmailAddress),
        cancellationToken);

    var selector = context.Select("user").FirstOrDefault()?.AsSelector<User>();
    var query = new QueryContext<User>(selector);

    return isSuccess
        ? await mediator.Send(new GetUserByIdQuery(userId, query), cancellationToken)
        : throw new AggregateException(errors.ToDomainExceptions());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant