public CarvedRockMutation(ProductReviewRepository reviewRepository, ReviewMessageService messageService)
        {
            FieldAsync <ProductReviewType>(
                "createReview",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ProductReviewInputType> >
            {
                Name = "review"
            }),
                resolve: async context =>
            {
                var review = context.GetArgument <ProductReview>("review");
                await reviewRepository.AddReview(review);

                messageService.AddReviewAddedMessage(review);
                return(review);
            });

            FieldAsync <BooleanGraphType>(
                "deleteReview",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await context.TryAsyncResolve(
                           async c => await reviewRepository.DeleteReview(id)));
            });
        }
Пример #2
0
 public ApplicationMutation(ProductReviewRepository repo)
 {
     FieldAsync <ProductReviewType>(
         "createReview",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ProductReviewInputType> > {
         Name = "review"
     }),
         resolve: async context =>
     {
         var review = context.GetArgument <ProductReview>("review");
         return(await context.TryAsyncResolve(async c => await repo.AddReview(review)));
     });
 }
Пример #3
0
 public CarvedRockMutation(ProductReviewRepository reviewRepository, ReviewMessageService messageService)
 {
     FieldAsync <ProductReviewType>("createReview",
                                    arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ProductReviewInputType> >
     {
         Name = "review"
     }), resolve: async context =>
     {
         var review = context.GetArgument <ProductReview>("review");
         await reviewRepository.AddReview(review);
         messageService.AddReviewAddedMessage(review);
         return(review);
     });
 }
Пример #4
0
        public CarvedRockMutation(ProductReviewRepository reviewRepository, ReviewMessageService messageService)
        {
            FieldAsync <ProductReviewType>( //ProductReviewType --> definuje ze tento objekt bude vrateny po tom ako bude mutation vykonana
                "createReview",             //poziadavka na vytvorenie review
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ProductReviewInputType> > {
                Name = "review"
            }                                                                                       //pozadovany argument
                    ),
                resolve: async context =>
            {
                var review = context.GetArgument <ProductReview>("review");    //ziskanie argumentu a resolvovanie do entity objektu
                //return await context.TryAsyncResolve(async c => await reviewRepository.AddReview(review));
                //vystup z AddReview je pouzitim "TryAsyncResolve" monitorovany (???) , ak je vytvorenie uspesne, review je navratene normalne
                //ak sa vsak vyskytne exception pri volani repository, exception je catchnuta a pridana do ErrorListu ktory je vrateny klientovi aj ked je API nastavena pre not-expose exception

                await reviewRepository.AddReview(review);
                messageService.AddReviewAddedMessage(review);     //po pridani review su subscriberi notifikovani
                return(review);
            }
                );
        }
Пример #5
0
        // Adding, updating, deleting data
        public CarvedRockMutation(ProductReviewRepository reviewRepository, ProductRepository productRepository)
        {
            // ProductReviewType is going to be returned when mutation is done
            FieldAsync <ProductReviewType>(
                "createReview",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ProductReviewInputType> > {
                Name = "review"
            }),
                resolve: async context =>
            {
                // Conversion from GraphType to Entity
                var review = context.GetArgument <ProductReview>("review");

                // The outcome of AddReview is monitored, exception will be catched and added to the error list even when the API is configured to not expose exceptions
                return(await context.TryAsyncResolve(
                           async c => await reviewRepository.AddReview(review)));
            });

            Field <StringGraphType>(
                "deleteProduct",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "productId"
            }),
                resolve: context =>
            {
                var productId = context.GetArgument <int>("productId");
                var product   = productRepository.GetOne(productId).Result;
                if (product == null)
                {
                    context.Errors.Add(new ExecutionError("Couldn't find product in db."));
                    return(null);
                }

                productRepository.Delete(product);
                return($"The owner with the id: {productId} has been successfully deleted from db.");
            }
                );
        }