예제 #1
0
 public ProductMutation(ProductReviewManager reviewRepository)
 {
     FieldAsync <ProductReviewGraph>(
         "createReview",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <ProductReviewInputGraph> > {
         Name = "review"
     }),
         resolve: async context =>
     {
         var review = context.GetArgument <ProductReview>("review");
         return(await context.TryAsyncResolve(
                    async c => await reviewRepository.AddReview(review)));
     });
 }
예제 #2
0
        public ProductGraph(ProductReviewManager productReviewManager, IDataLoaderContextAccessor dataLoaderAccessor)
        {
            Field(t => t.Id);
            Field(t => t.Name);
            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 <ProductTypeGraph>("Type", "The type of product");


            Field <ListGraphType <ProductReviewGraph> >(
                "reviews",
                resolve: context =>
            {
                var loader =
                    dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, ProductReview>(
                        "GetReviewsByProductId", productReviewManager.GetForProducts);
                return(loader.LoadAsync(context.Source.Id));
            });
        }
예제 #3
0
 public ProductReviewController()
 {
     this.reviewManager = new ProductReviewManager();
 }