using Books.Api.Domain.Companies; using Books.Api.EventFlow.Repositories; using Books.Api.GraphQL.Types; using GraphQL; using GraphQL.Types; namespace Books.Api.GraphQL.Queries; public class BooksQuery : ObjectGraphType { public BooksQuery() { Name = "Query"; Description = "Root query for the Books API"; // companies: [CompanyType] Field>("companies") .Description("Get all companies") .ResolveAsync(async ctx => { var repository = ctx.RequestServices!.GetRequiredService(); return await repository.GetAllAsync(ctx.CancellationToken); }); // company(id: ID!): CompanyType Field("company") .Description("Get a company by ID") .Argument>("id", "The company ID") .ResolveAsync(async ctx => { var id = ctx.GetArgument("id"); var repository = ctx.RequestServices!.GetRequiredService(); var companies = await repository.GetByIds([CompanyId.With(id)], ctx.CancellationToken); return companies.FirstOrDefault(); }); } }