I am using HotChocolate library to work with GraphQL via .NET. I already can get all objects, that are stored in db, using this query:
query
{
news
{
title
description
}
}
But I need to have an opportunity, to select object with specific id like in this query:
query
{
news(id: 5)
{
title
description
}
}
But I'm getting the following exception
Unknown argument "id" on field "Query.news".
I use this code to get all news from database and return it to a client:
[UseDbContext(typeof(Context.Context))]
[UseFiltering]
[UseSorting]
public IQueryable<Entities.News> GetNews([ScopedService] Context.Context context)
{
return context.News;
}
Also I tried to get an object by id using this code:
[UseDbContext(typeof(Context.Context))]
[UseFiltering]
[UseSorting]
public Entities.News GetNews(int id, [ScopedService] Context.Context context)
{
return context.News.Find(id);
}
But I іtill have the exception when trying to get it by id