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

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

Open robcecil opened this issue 2 years ago • 3 comments

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

robcecil avatar May 26 '22 13:05 robcecil

   `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

arkum avatar Jun 05 '22 00:06 arkum

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.

JohanHeyvaert avatar Aug 18 '22 07:08 JohanHeyvaert

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

stephenstroud avatar May 09 '23 00:05 stephenstroud