public ProductAssociationType(IDataLoaderContextAccessor dataLoader, IMediator mediator) { Name = "ProductAssociation"; Description = "product association."; Field(d => d.Type); Field(d => d.Priority); Field("Quantity", x => x.Quantity, nullable: true, type: typeof(IntGraphType)); Field(d => d.AssociatedObjectId); Field(d => d.AssociatedObjectType); var productField = new FieldType { Name = "product", Type = GraphTypeExtenstionHelper.GetActualType <ProductType>(), Resolver = new AsyncFieldResolver <ProductAssociation, object>(async context => { var loader = dataLoader.Context.GetOrAddBatchLoader <string, ExpProduct>("associatedProductLoader", (ids) => LoadProductsAsync(mediator, ids)); // IMPORTANT: In order to avoid deadlocking on the loader we use the following construct (next 2 lines): var loadHandle = loader.LoadAsync(context.Source.AssociatedObjectId); return(await loadHandle); }) }; AddField(productField); }
public Talk(FeedbackService feedbackService, IDataLoaderContextAccessor dataLoaderAccessor, SpeakersRepository speakersRepository) { Field(t => t.Id); Field(t => t.Title); Field(t => t.Description); Field(t => t.SpeakerId); //Field(name: "speaker", type: typeof(Speaker), resolve: context => context.Source.Speaker); ///loads the feedbacks for a talk in one go Field <ListGraphType <FeedbackType> >( "feedbacks", resolve: context => { //his is an example of using a DataLoader to batch requests for loading a collection of items by a key. //This is used when a key may be associated with more than one item. LoadAsync() is called by the field resolver for each User. var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, Conference.Service.Feedback>( "GetReviewsByTalkId", feedbackService.GetAllInOneGo); return(loader.LoadAsync(context.Source.Id)); }); Field <ListGraphType <Speaker> >( "speakers", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, Data.Entities.Speaker>("GetSpeakersForTalk", speakersRepository.GetAllSpeakersInOneGo); return(loader.LoadAsync(context.Source.Id)); }); }
public ProductType(ProductReviewRepository reviewRepository, IDataLoaderContextAccessor dataLoaderAccessor) { // Basic fields, GraphQL can map them Field(t => t.Id); Field(t => t.Name).Description("The name of the product."); // .Description() adds description for the field Field(t => t.Description); Field(t => t.IntroducedAt); Field(t => t.PhotoFileName); Field(t => t.Price); Field(t => t.Rating); Field(t => t.Stock); // Enums, scalar types (int, string) Field <ProductTypeEnumType>("Type", "The type of product"); // Name, desc shown in schema explorer // Complex types (classes), loads reviews for each product Field <ListGraphType <ProductReviewType> >( "reviews", resolve: context => { var user = (ClaimsPrincipal)context.UserContext; // (ClaimsPrincipal) => just changing type // user. ... // authorization // Cashes data so we don't have many unnecessary queries // DataLoader needs to be added in Startup config // GetOrAddCollectionBatchLoader will crate a new or use an existing data loader by name // data loader uses a dictionary to cash data, has INT as a key and ProductReview object as a value // Gets data through method GetForProducts from repository var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, ProductReview>( "GetReviewsByProductId", reviewRepository.GetForProducts); return(loader.LoadAsync(context.Source.Id)); // Source if the Product entity }); }
public ProductType(StoreDbContext dbContext, IDataLoaderContextAccessor dataLoaderAccessor) { Field(p => p.Name); Field(p => p.Price); // simple solution //Field<ManufacturerType>("Manufacturer", resolve: ctx => ctx.Source.Manufacturer); // solution with data loader Func <IEnumerable <int>, Task <IDictionary <int, Manufacturer> > > getManufacturersFunc = async(ids) => { return(await dbContext.Manufacturers.Where(m => ids.Contains(m.ManufacturerId)).ToDictionaryAsync(m => m.ManufacturerId, m => m)); }; Field <ManufacturerType>( "manufacturer", resolve: ctx => { var loader = dataLoaderAccessor.Context.GetOrAddBatchLoader <int, Manufacturer>( "GetManufacturerByManufacturerId", getManufacturersFunc ); return(loader.LoadAsync(ctx.Source.ManufacturerId)); } ); }
public MonthlyItemResultType(IDataLoaderContextAccessor dataLoaderAccessor) { Field("Year", t => t.Year, nullable: false, type: typeof(IntGraphType)); Field("Month", t => t.Month, nullable: false, type: typeof(IntGraphType)); Field("Items", t => t.Items, nullable: false, type: typeof(ListGraphType <ItemType>)); Field("Amount", t => t.Amount, nullable: false, type: typeof(DecimalGraphType)); }
public ProductRecommendationType( IMediator mediator, IDataLoaderContextAccessor dataLoader) { Name = "ProductRecommendation"; Description = "Product recommendation object"; Field(d => d.ProductId).Description("The unique ID of the product."); Field(d => d.Scenario).Description("The recommendation scenario name."); Field(d => d.Score).Description("The recommendation relevance score."); var productField = new FieldType { Name = "product", Type = GraphTypeExtenstionHelper.GetActualType <ProductType>(), Resolver = new AsyncFieldResolver <ProductRecommendation, object>(async context => { var includeFields = context.SubFields.Values.GetAllNodesPaths().Select(x => x.TrimStart("items.")).ToArray(); var loader = dataLoader.Context.GetOrAddBatchLoader <string, ExpProduct>($"recommendedProducts", (ids) => LoadProductsAsync(mediator, new LoadProductRequest { Ids = ids.ToArray(), IncludeFields = includeFields.ToArray() })); // IMPORTANT: In order to avoid deadlocking on the loader we use the following construct (next 2 lines): var loadHandle = loader.LoadAsync(context.Source.ProductId); return(await loadHandle); }) }; AddField(productField); }
public DigitalCatalogSchema(IMediator mediator, IDataLoaderContextAccessor dataLoader, ICurrencyService currencyService, IStoreService storeService) { _mediator = mediator; _dataLoader = dataLoader; _currencyService = currencyService; _storeService = storeService; }
public ProductRecommendationType( IMediator mediator, IDataLoaderContextAccessor dataLoader) { Name = "ProductRecommendation"; Description = "Product recommendation object"; Field(d => d.ProductId).Description("The unique ID of the product."); Field(d => d.Scenario).Description("The recommendation scenario name."); Field(d => d.Score).Description("The recommendation relevance score."); var productField = new FieldType { Name = "product", Type = GraphTypeExtenstionHelper.GetActualType <ProductType>(), Resolver = new FuncFieldResolver <ProductRecommendation, IDataLoaderResult <ExpProduct> >(context => { var includeFields = context.SubFields.Values.GetAllNodesPaths().ToArray(); var loader = dataLoader.Context.GetOrAddBatchLoader <string, ExpProduct>($"recommendedProducts", (ids) => LoadProductsAsync(mediator, context, ids, includeFields)); return(loader.LoadAsync(context.Source.ProductId)); }) }; AddField(productField); }
public MortgageType(IDataLoaderContextAccessor _accessor) { Field(t => t.InitialValue, nullable: false, type: typeof(DecimalGraphType)); Field(t => t.InitiatedAt, nullable: false, type: typeof(DateGraphType)); Field(t => t.AmortisationPeriodInMonths, nullable: false, type: typeof(IntGraphType)); Field(t => t.InterestRate, nullable: false, type: typeof(DecimalGraphType)); }
public Task <TEntity> LoadBatchedEntityAsync <TEntity>( string loaderKey, int key, Func <TEntity, int> keySelector, IDataLoaderContextAccessor accessor) where TEntity : class { return(accessor.Context.GetOrAddBatchLoader <int, TEntity> ( loaderKey, async(keys, token) => { Dictionary <int, TEntity> dictionary; await using (var context = _serviceProvider.GetService <ATIDSXEContext>()) { Expression <Func <TEntity, int> > selector = (Expression <Func <TEntity, int> >)(entity => keySelector(entity)); Expression <Func <TEntity, bool> > predicate = (Expression <Func <TEntity, bool> >)(entity => keySelector(entity) == 2); dictionary = await context.Set <TEntity>() .Where(predicate) .ToDictionaryAsync(keySelector, token); } return dictionary; } ).LoadAsync(key)); }
public InventoryQuery(IDataStore dataStore, IDataLoaderContextAccessor accessor) { Field <ItemType>( "item", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "barcode" }), resolve: context => { var barcode = context.GetArgument <string>("barcode"); return(dataStore.GetItemByBarcode(barcode)); }); Field <ListGraphType <ItemType>, IEnumerable <Item> >() .Name("Items") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddLoader("GetAllItems", () => dataStore.GetItemsAsync()); return(loader.LoadAsync()); }); Field <ListGraphType <OrderType>, IEnumerable <Order> >() .Name("Orders") .ResolveAsync(ctx => dataStore.GetOrdersAsync()); Field <ListGraphType <CustomerType>, IEnumerable <Customer> >() .Name("Customers") .ResolveAsync(ctx => dataStore.GetCustomersAsync()); Field <ListGraphType <OrderItemType>, IEnumerable <OrderItem> >() .Name("OrderItems") .ResolveAsync(ctx => dataStore.GetOrderItemsAsync()); }
public SystemProcessOperationGraphType( ISystemProcessRepository operationRepository, IDataLoaderContextAccessor dataLoaderAccessor) { this.AuthorizeWith(PolicyManifest.UserPolicy); this.Field(i => i.Id).Description("Identifier for the system process operation"); this.Field(i => i.SystemProcessId).Description("Identifier for the system process"); this.Field <SystemProcessGraphType>( "process", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddLoader( $"GetSystemProcessById-{context.Source.SystemProcessId}", () => operationRepository.GetForId(context.Source.SystemProcessId)); return(loader.LoadAsync()); }); this.Field(i => i.OperationState).Description("The last state of the operation"); this.Field(i => i.OperationStart).Type(new DateTimeGraphType()) .Description("The time the operation started at in the real world (UTC)"); this.Field(i => i.OperationEnd, true).Type(new DateTimeGraphType()) .Description("The time the operation ended at in the real world (UTC)"); }
public NavigationMenuType(MenuRepository menuRepository, IDataLoaderContextAccessor dataLoaderAccessor) { Field(t => t.Id); Field(t => t.Name); Field(t => t.Description); Field(t => t.ApplicationId); Field(t => t.ActionRoute, nullable: true); Field(t => t.ImageUrl); Field(t => t.ParentId, nullable: true); Field(t => t.Sort); Field(t => t.IsActive); Field(t => t.Created, nullable: true); Field(t => t.CreatedBy); Field(t => t.Modified, nullable: true); Field(t => t.ModifiedBy); Field <ListGraphType <NavigationMenuType> >( "Children", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, NavigationMenu>( "GetNavigationMenuChildren", menuRepository.GetNavigationMenusChildren); return(loader.LoadAsync(context.Source.Id)); }); Field <ListGraphType <RoleNavigationMenuType> >("RoleNavigationMenus", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, RoleNavigationMenu>( "GetRoleNavigationMenus", menuRepository.GetRoleNavigationMenus); return(loader.LoadAsync(context.Source.Id)); }); }
private void InitDependencies(IDataLoaderContextAccessor accessor, IPersonManager personManager, IUnitManager unitManager) { Accessor = accessor; PersonManager = personManager; UnitManager = unitManager; }
public OrderType (IDataLoaderContextAccessor dataLoaderAccessor, AllocationsRepository allocationsRepository) { Field(t => t.OrderId); Field(t => t.OmsOrderId); Field(t => t.OmsOrderVersionId); Field(t => t.GamId); Field(t => t.SecurityType); Field(t => t.TradeDate); Field(t => t.Trader); Field(t => t.SourceListCode); Field(t => t.SourceListitemCode); Field(t => t.CreatedDate); Field <IntGraphType>().Name("allocationCount").ResolveAsync(async(context) => { return(await allocationsRepository.GetCountForOrder(context.Source.OrderId)); }); // Using dataloader // ---------------- Field <ListGraphType <AllocationType> >( "allocations", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, Allocations>( "GetAllocationsByOrderId", allocationsRepository.GetForOrders); return(loader.LoadAsync(context.Source.OrderId)); }); }
public ProductType(ProductReviewRepository reviewRepository, IDataLoaderContextAccessor dataLoaderAccessor) { Field(t => t.Id); Field(t => t.Name).Description("The name of the product"); Field(t => t.Description); Field(t => t.IntroducedAt).Description("When the product was first introduced in the catalog"); Field(t => t.PhotoFileName).Description("The file name of the photo so the client can render it"); Field(t => t.Price); Field(t => t.Rating).Description("The (max 5) star customer rating"); Field(t => t.Stock); Field <ProductTypeEnumType>("Type", "The type of product"); Field <ListGraphType <ProductReviewType> >( "reviews", //definuje nazov ktory je treba zadavat do query pri dopytovani //resolve: context => reviewRepository.GetForProduct(context.Source.Id) //definicia sposobu resolvovania resolve: context => { var user = (ClaimsPrincipal)context.UserContext; //ziskanie uzivatela z kontextu var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, ProductReview>("GetReviewsByProductId", reviewRepository.GetForProducts); //data loader je ziskany volanim metody GetOrAddCollectionBatchLoader (vytvori alebo vrati data loader podla nazvu) //data loader vyuziva cache dictionary pre uchovanie dat return(loader.LoadAsync(context.Source.Id)); } ); //je vykonavanych vela DB queries --> pre ziskanie zoznamu produktov + pre kazdy produkt je vykonane dopytovanie pre ziskanie ProductReview z DB --> mozne vyuzit Data loader //pri vyuziti Data Loaderu je ziskany zoznam produktov, nasledne su ziskane ProductPreview pre vsetky produkty, ktore su uchovane v DataLoadery (vykonane 2 dopyty do DB) }
public ManufacturerInfoType(IDataLoaderContextAccessor dataLoader) { Description = "Manufaturer info"; Field(x => x.Id, type: typeof(IdGraphType)).Description("Guid property"); Field(x => x.Name, type: typeof(IdGraphType)).Description("Name of the manufacturer"); }
public StationType( IDataLoaderContextAccessor accessor, IRepositoryWrapper repository) { Name = nameof(Station); Field(_ => _.Id, type: typeof(NonNullGraphType <IdGraphType>)).Description("Eindeutige unveränderliche ID."); Field(_ => _.Number).Description("Pegelnummer"); Field(_ => _.Shortname).Description("Pegelname (max. 40 Zeichen)"); Field(_ => _.Longname).Description("Pegelname (max. 255 Zeichen)"); Field(_ => _.Km).Description("Flusskilometer"); Field(_ => _.Agency).Description("Wasserstraßen- und Schifffahrtsamt"); Field(_ => _.Longitude).Description("Längengrad in WGS84 Dezimalnotation"); Field(_ => _.Latitude).Description("Breitengrad in WGS84 Dezimalnotation"); Field(_ => _.Created); Field(_ => _.Updated, nullable: true); FieldAsync <WaterType, Water>( nameof(Station.Water), description: "The Water on which the measuring Station is located", resolve: async context => { var loader = accessor.Context.GetOrAddBatchLoader <Guid, Water>("GetWatersById", repository.Water.GetWatersByIdAsync); return(await loader.LoadAsync(context.Source.WaterFk)); }); }
public UnsolicitedTradingType (IDataLoaderContextAccessor dataLoaderAccessor) { Field(t => t.TradeId); Field(t => t.FirstDealDate); Field(t => t.FirstAuthorisedDate); Field(t => t.ReportedDate); Field(t => t.InputDate); Field(t => t.AssetIdentifier); Field(t => t.AssetClass); Field(t => t.AssetSubClass); Field(t => t.Description); Field(t => t.InputBy); Field(t => t.AuthorisedBy); Field(t => t.WorkedBy); Field(t => t.FilledBy); Field(t => t.PlacedBy); Field(t => t.ReportedBy); Field(t => t.Counterparty); Field(t => t.Reason); Field(t => t.DealDate); Field(t => t.AuthorisedDate); Field(t => t.FilledDate); Field(t => t.Status); Field(t => t.StatusCode); Field(t => t.UserId); Field(t => t.UpdatedDate); }
public CustomerType(IDataLoaderContextAccessor accessor, Func <IOrderRepository> funcCustomerRepository) : base() { Field(x => x.Id).Description("Customer Id"); Field(x => x.ContactTitle).Description("Contact Title"); Field(x => x.ContactName).Description("Customer Contact Name"); Field(x => x.CompanyName).Description("Company name"); FieldAsync <ListGraphType <OrderType> >("Orders", "Orders of the client", null, resolve: async context => { var userContext = (ClaimsPrincipal)context.UserContext; if (userContext.HasClaim(x => x.Type == "customclaim" && x.Value == "customvalue")) { // Get or add a collection batch loader with the key "GetOrdersByUserId" // The loader will call GetOrdersByUserIdAsync with a batch of keys var repository = funcCustomerRepository(); var orderLoader = accessor.Context.GetOrAddCollectionBatchLoader <int, Order>("GetOrdersByCustomerId", repository.GetOrdersByCustomerId); // Add this customerId to the pending keys to fetch data for // The task will complete with an IEnumberable<Order> once the fetch delegate has returned return(await orderLoader.LoadAsync(context.Source.Id)); //return await funcCustomerRepository.Invoke().GetOrders(context.Source.Id); //return await context.Source.CustomerOrdersNavigation.Select(x=>x).ToList() } else { context.Errors.Add(new GraphQL.ExecutionError("Unauthorized user", new UnauthorizedAccessException())); return(null); } }); }
public ProjectType( IDataLoaderContextAccessor dataLoaderAccessor, IRequirementRepository requirementRepository, IProjectRepository projectRepository) { Field(x => x.Id); Field(x => x.Title); Field(x => x.Description); Field(x => x.RepositoryUrl); Field(x => x.ProjectUrl); Field(x => x.CreatedAt); Field <ProjectTypeEnumType>(nameof(ProjectModel.Type)); Field <ProjectType>( nameof(ProjectModel.ParentProject), resolve: context => context.Source.ParentProjectId.HasValue ? projectRepository.GetById(context.Source.ParentProjectId.Value) : null); Field <ListGraphType <ProjectType> >( nameof(ProjectModel.Subprojects), resolve: context => projectRepository.GetSubprojects(context.Source.Id)); Field <ListGraphType <RequirementType> >( nameof(ProjectModel.Requirements), resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, RequirementModel>( "GetRequirementsByProjectId", requirementRepository.GetForProjects); return(loader.LoadAsync(context.Source.Id)); }); }
public DroidQuery(IDataLoaderContextAccessor accessor, IDroidRepository droids) : base(accessor) { Field <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "id" }, new QueryArgument <StringGraphType> { Name = "name" } ), resolve: context => { var id = context.GetArgument <int>("id"); var name = context.GetArgument <string>("name"); return(Defer("GetDroid", () => id > 0 ? droids.Get(id) : droids.Get(name) )); }); Field <ListGraphType <DroidType> >( "droids", resolve: context => Defer("GetDroids", () => droids.Get()) ); }
public SameUserTradingType (IDataLoaderContextAccessor dataLoaderAccessor) { Field(t => t.TradeId); Field(t => t.UpdatedByPlaced); Field(t => t.UpdatedByDatePlaced); Field(t => t.UpdatedByAuthorised); Field(t => t.UpdatedByDateAuthorised); Field(t => t.AssetIdentifier); Field(t => t.AssetClass); Field(t => t.AssetSubClass); Field(t => t.Description); Field(t => t.InputBy); Field(t => t.AuthorisedBy); Field(t => t.PlacedBy); Field(t => t.FilledBy); Field(t => t.InputDate); Field(t => t.AuthorisedDate); Field(t => t.Counterparty); Field(t => t.Reason); Field(t => t.FilledDate); Field(t => t.Status); Field(t => t.StatusCode); Field(t => t.UserId); Field(t => t.UpdatedDate); }
public OrderType(IUser user, IProduct product, IDataLoaderContextAccessor accessor) { Name = "Order"; Description = "Order fields"; Field(x => x.OrderId).Description("Order Id"); Field(x => x.Quantity).Description("Product quantity"); Field <UserType, User>() .Name("User") .Description("the user who places the order") .ResolveAsync(context => { return(user.GetByIdAsync(context.Source.UserId)); }); Field <ListGraphType <UserType>, IEnumerable <User> >() .Name("Users") .Description("the user who places the order") .ResolveAsync(ctx => { var ordersLoader = accessor.Context.GetOrAddCollectionBatchLoader <int, User>("GetReviewsByUserId", user.GetByIdAsync); return(ordersLoader.LoadAsync(ctx.Source.UserId)); }); Field <ProductType>("Product", Description = "Ordered product", resolve: context => { return(product.GetByIdAsync(context.Source.ProductId)); }); }
public OrderType(IDataLoaderContextAccessor accessor, IUsersStore users, IOrdersStore orders) { Name = "Order"; Field(x => x.OrderId); Field(x => x.OrderedOn); Field <UserType, User>() .Name("User") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddBatchLoader <int, User>("GetUsersById", users.GetUsersByIdAsync); return(loader.LoadAsync(ctx.Source.UserId)); }); Field <ListGraphType <OrderItemType>, IEnumerable <OrderItem> >() .Name("Items") .ResolveAsync(ctx => { var loader = accessor.Context.GetOrAddCollectionBatchLoader <int, OrderItem>("GetOrderItemsById", orders.GetItemsByOrderIdAsync); return(loader.LoadAsync(ctx.Source.OrderId)); }); }
public ProductType(ProductReviewRepository productReviewRepository, IDataLoaderContextAccessor dataLoaderAccessor) { Field(t => t.Id); Field(t => t.Name).Description("The name of the product"); Field(t => t.Description); Field(t => t.IntroducedAt).Description("When the product was first introduced in the catalog"); Field(t => t.PhotoFileName).Description("The file name of the photo so the client can render it"); Field(t => t.Price); Field(t => t.Rating).Description("The (max 5) star customer rating"); Field(t => t.Stock); Field <ProductTypeEnumType>("Type", "The type of product"); Field <ListGraphType <ProductReviewType> >( "reviews", resolve: context => //productReviewRepository.GetForProduct(context.Source.Id)); { // var user = (ClaimsPrincipal)context.UserContext; //user.cl var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, ProductReview>( "GetReviewsByProductId", productReviewRepository.GetForProducts); return(loader.LoadAsync(context.Source.Id)); }); }
public SubmissionObject(IDataLoaderContextAccessor accessor) { this.Field(x => x.Id); this.Field(x => x.ProblemId); this.Field(x => x.LanguageName); this.Field(x => x.Date); this.Field(x => x.Time); this.Field(x => x.Memory); this.Field(x => x.Points); this.Field(x => x.Status); this.Field(x => x.Source); this.FieldAsync <ListGraphType <SubmissionTestCaseObject>, List <SubmissionTestCase> >( nameof(Submission.TestCases), resolve: async context => (await accessor .Context .GetOrAddCollectionBatchLoader <int, SubmissionTestCase>( "GetTestCasesBySubmissionId", submissionIds => Task.FromResult(Database .TestCases .Where(t => submissionIds.Contains(t.SubmissionId)) .ToLookup(t => t.SubmissionId))) .LoadAsync(context.Source.Id)) .ToList()); }
public GqlHeroVoiceActor(FehContextFactory dbContextFactory, IDataLoaderContextAccessor accessor) { this.Name = nameof(HeroVoiceActor); this.Field(nameof(HeroVoiceActor.HeroId), x => x.HeroId); this.Field(nameof(HeroVoiceActor.Id), x => x.Id); this.Field(nameof(HeroVoiceActor.Language), x => (int)x.Language); this.Field(nameof(HeroVoiceActor.Sort), x => x.Sort); this.Field(nameof(HeroVoiceActor.VoiceActorId), x => x.VoiceActorId); /* Data Loader */ this .Field <GqlVoiceActor, VoiceActor>() .Name(nameof(HeroVoiceActor.VoiceActor)) .ResolveAsync( (context) => { var service = new VoiceActorService(dbContextFactory.CreateDbContext()); var loader = accessor.Context.GetOrAddBatchLoader <int, VoiceActor>( $"{nameof(VoiceActor)}_{nameof(VoiceActorService.GetByIdsAsync)}", service.GetByIdsAsync ); return(loader.LoadAsync(context.Source.VoiceActorId)); } ); }
public CarGraphType(IDataLoaderContextAccessor accessor, IGraphStore <Brand> brandStore, IGraphStore <Combustion> combustionStore) { Field(x => x.Id).Description("Id del modelo del carro"); Field(x => x.Placa).Description("Placa del modelo del carro"); Field(x => x.numeroPuertas).Description("numeroPuertas del modelo del carro"); Field(x => x.Modelo).Description("Modelo del modelo del carro"); Field <BrandGraphType, Brand>() .Name("Brand") .ResolveAsync(context => { var loader = accessor.Context.GetOrAddBatchLoader <int?, Brand>("GetUsersById", ids => brandStore.GetUsersByIdAsync(ids, CancellationToken.None)); return(loader.LoadAsync(context.Source.BrandKey)); }); Field <CombustionGraphType, Combustion>() .Name("Combustion") .ResolveAsync(context => { var loader = accessor.Context.GetOrAddBatchLoader <int?, Combustion>("GetUsersById", ids => combustionStore.GetUsersByIdAsync(ids, CancellationToken.None)); return(loader.LoadAsync(context.Source.CombustionKey)); }); }
public AssignmentType(IAssignmentRepository assignmentRepository, IDataLoaderContextAccessor dataLoader, IAssignmentStatusRepository statusRepository, ICategoryRepository categoryRepository, ISubTaskRepository subTaskRepository) { Field(t => t.Id); Field(t => t.Name); Field(t => t.Description); Field(t => t.DueDate); Field(t => t.Important); Field <StatusType, AssignmentStatus>() .Name("TaskStatus") .ResolveAsync(ctx => { var loader = dataLoader.Context.GetOrAddBatchLoader <int, AssignmentStatus>( "GetStatus", statusRepository.GetStatusForAssignments); return(loader.LoadAsync(ctx.Source.Id)); }); Field <CategoryType, Category>() .Name("TaskCategory") .ResolveAsync(context => { var loader = dataLoader.Context.GetOrAddBatchLoader <int, Category>( "GetCategory", categoryRepository.GetCategoryForAssignments); return(loader.LoadAsync(context.Source.Id)); }); Field <ListGraphType <SubTaskType>, IEnumerable <SubTask> >() .Name("SubTasks") .ResolveAsync(context => { var loader = dataLoader.Context.GetOrAddCollectionBatchLoader <int, SubTask>( "GetSubTasks", subTaskRepository.GetSubTasksForAssignments); return(loader.LoadAsync(context.Source.Id)); }); }