1

Hi I have the following query class:

public class haProgrammesQuery
    {
        [UseFiltering]
        public async Task<IQueryable<User>> GetUsers([Service] haProgrammesContext Context) => Context.Users;
        
        
        [UseFiltering]
        [UseFirstOrDefault]
        public async Task<IQueryable<User>> GetUserById([Service] haProgrammesContext Context, string Id) { 
        return Context.Users.Where(u => u.UserId.ToString() == Id);
        } 
    }

which works fine in playground using the query:

query {
users{
    userId
    name
  }
}

but the query

query{
 userById(id:"fd8b8670-60cf-451a-8fea-0fc0c69cde3a")
  {
    name
  }
}

calls the UserById method (checked using a breakpoint) but the string Id argument is null and thus the response is null back to playground.

I have also played with a basic echo method to return the string argument back but that also has a null argument received and also played with async Task<IQueryable<User>> (as this version is and yes I know it is not using awaiting) and also just the standard IQueryable<User> just to se if there was anything there - what am I dong wrong?!

Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343
haPartnerships
  • 335
  • 1
  • 2
  • 13

1 Answers1

2

Hotchocolate (or some form of middleware along the way) interprets the argument name and includes a lower case first letter to it when placing it in the schema

therefore

        [UseFiltering]
        [UseFirstOrDefault]
        public async Task<IQueryable<User>> GetUserById([Service] haProgrammesContext Context, string Id) { 
        return Context.Users.Where(u => u.UserId.ToString() == Id);
        } 

Needs to be

        [UseFirstOrDefault]
        public async Task<IQueryable<User>> GetUserById([Service] haProgrammesContext Context, string id) { 
        return Context.Users.Where(u => u.UserId.ToString() == id);
        } 

for it to run (lowercase i on Id)

As such... MyCamelCaseArgumentName needs to be myCamelCaseArgumentName etc...

haPartnerships
  • 335
  • 1
  • 2
  • 13