ChilliCream / graphql-workshop

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

"There was no argument with the name `speaker` found on the field `sessions`." #101

Closed robcecil closed 1 month ago

robcecil commented 2 years ago

When completing section 3 "Understanding Dataloaders", with the introduction of SpeakerType, and SpeakerResolvers, I'm getting the error:

{
  "errors": [
    {
      "message": "There was no argument with the name `speaker` found on the field `sessions`.",
      "locations": [
        {
          "line": 5,
          "column": 6
        }
      ],
      "path": [
        "speakers",
        0,
        "sessions"
      ],
      "extensions": {
        "fieldName": "sessions",
        "argumentName": "speaker"
      }
    }
  ]
}
arkum commented 2 years ago
   `private class SpeakerResolvers
    {

        public async Task<IEnumerable<Session>> GetSessionAsync(
            [Parent]Speaker speaker,
            [ScopedService]ApplicationDbContext dbContext,
            SessionByIdDataLoader sessionByIdDataLoader,
            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(cancellationToken);
            return await sessionByIdDataLoader.LoadAsync(sessionIds, cancellationToken);
        }

    }`

marking the first parameter with the Parent attribute solved it for me. specified in v11 to v12 the upgrade guide https://chillicream.com/docs/hotchocolate/api-reference/migrate-from-11-to-12#resolvers

JohanHeyvaert commented 2 years ago

Should be mentioned in the workshop I think. Had the same problem today and took me some time to figure it out. I see that other people also encountered this issue.

stephenstroud commented 1 year ago

Thanks for posting this, wasted a little bit of time on it.

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.