ChilliCream / graphql-workshop

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

[Session 3] Speaker schema not updated #109

Closed weirdyang closed 1 year ago

weirdyang commented 1 year ago

image

 public class SpeakerType : ObjectType<Speaker>
    {
        protected override void Configure(IObjectTypeDescriptor<Speaker> descriptor)
        {
            descriptor
                .Field(t => t.SessionSpeakers)
                .ResolveWith<SpeakerResolvers>(t => t.GetSessionsAsync(default!, default!, default!, default))
                .UseDbContext<ApplicationDbContext>()
                .Name("sessions");
        }

        private class SpeakerResolvers
        {
            public async Task<IEnumerable<Session>> GetSessionsAsync(
                Speaker speaker,
                ApplicationDbContext dbContext,
                SessionByIdDataLoader sessionById,
                CancellationToken cancellationToken)
            {
                int[] sessionIds = await dbContext.Speakers
                    .Where(s => s.Id == speaker.Id)
                    .Include(s => s.SessionSpeakers)
                    .SelectMany(s => s.SessionSpeakers.Select(t => t.SessionId))
                    .ToArrayAsync();

                return await sessionById.LoadAsync(sessionIds, cancellationToken);
            }
        }
    }
            builder.Services
              .AddGraphQLServer()
              .RegisterDbContext<ApplicationDbContext>(DbContextKind.Pooled)
              .AddQueryType<Query>()
              .AddMutationType<SpeakerMutation>()
              .AddType<SpeakerType>()
              .AddDataLoader<SpeakerByIdDataLoader>()
              .AddDataLoader<SessionByIdDataLoader>();

I've updated the speaker model, added the speakerType, ran the migration and updated the database, however the schema in the browser still does not show the SessionSpeakers collection. image Has there been any changes between the versions?

weirdyang commented 1 year ago

sorry realised it was renamed to sessions