ChilliCream / graphql-workshop

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

RenameSession Error #89

Closed jason8448 closed 1 month ago

jason8448 commented 2 years ago

Hi! I want to try the get started found here: https://chillicream.com/docs/strawberryshake/get-started and the following project is generated. I found that the RenameSession is not work correctly after click the Save button. The problem occurred in the graphql server .

The error msg as follows: https://files.slack.com/files-pri/TD98NH6TS-F02RX8AQ5FZ/image.png https://files.slack.com/files-pri/TD98NH6TS-F02RVR6BTEK/image.png

And the function should be modified as follows:

[UseApplicationDbContext]
    public async Task<RenameSessionPayload> RenameSessionAsync(
        RenameSessionInput input,
        [ScopedService] ApplicationDbContext context,
        [Service]ITopicEventSender eventSender)
    {
        var session = await context.Sessions.FindAsync( int.Parse( input.SessionId));

        if (session is null)
        {
            return new RenameSessionPayload(
                new UserError("Session not found.", "SESSION_NOT_FOUND"));
        }

        session.Title = input.Title;

        await context.SaveChangesAsync();

        await eventSender.SendAsync(
            nameof(SessionSubscriptions.OnSessionScheduledAsync),
            session.Id);

        return new RenameSessionPayload(session);
    }
glen-84 commented 1 month ago

I'm closing this issue as outdated, as we have an updated workshop on the main branch, for Hot Chocolate 14.