public CoolStoreSchema(ICoolStoreResolverService resolverService)
        {
            var schema    = FromIdlAsync().Result;
            var resolvers = new CoolStoreResolvers(resolverService);

            CoolStore = SchemaTools.MakeExecutableSchemaWithIntrospection(
                schema,
                resolvers,
                resolvers).Result;
        }
Exemple #2
0
        public CoolStoreResolvers(ICoolStoreResolverService resolverService)
        {
            this["Sample"] = new FieldResolverMap
            {
                { "name", PropertyOf <Sample>(m => m.Name) }
            };

            this["Product"] = new FieldResolverMap
            {
                { "id", PropertyOf <CatalogProductDto>(m => m.Id) },
                { "name", PropertyOf <CatalogProductDto>(m => m.Name) },
                { "price", PropertyOf <CatalogProductDto>(m => m.Price) },
                { "imageUrl", PropertyOf <CatalogProductDto>(m => m.ImageUrl) },
                { "desc", PropertyOf <CatalogProductDto>(m => m.Desc) }
            };

            this["Cart"] = new FieldResolverMap
            {
                { "id", PropertyOf <CartDto>(m => m.Id) },
                { "cartItemTotal", PropertyOf <CartDto>(m => m.CartItemTotal) },
                { "cartItemPromoSavings", PropertyOf <CartDto>(m => m.CartItemPromoSavings) },
                { "shippingTotal", PropertyOf <CartDto>(m => m.ShippingTotal) },
                { "shippingPromoSavings", PropertyOf <CartDto>(m => m.ShippingPromoSavings) },
                { "cartTotal", PropertyOf <CartDto>(m => m.CartTotal) },
                { "isCheckOut", PropertyOf <CartDto>(m => m.IsCheckOut) },
                { "items", PropertyOf <CartDto>(m => m.Items) }
            };

            this["CartItem"] = new FieldResolverMap
            {
                { "productId", PropertyOf <CartItemDto>(m => m.ProductId) },
                { "productName", PropertyOf <CartItemDto>(m => m.ProductName) },
                { "quantity", PropertyOf <CartItemDto>(m => m.Quantity) },
                { "price", PropertyOf <CartItemDto>(m => m.Price) },
                { "promoSavings", PropertyOf <CartItemDto>(m => m.PromoSavings) }
            };

            this["Inventory"] = new FieldResolverMap
            {
                { "id", PropertyOf <InventoryDto>(m => m.Id) },
                { "location", PropertyOf <InventoryDto>(m => m.Location) },
                { "quantity", PropertyOf <InventoryDto>(m => m.Quantity) },
                { "link", PropertyOf <InventoryDto>(m => m.Link) }
            };

            this["Query"] = new FieldResolverMap
            {
                { "samples", resolverService.GetSamplesAsync },
                { "products", resolverService.GetProductsAsync },
                { "product", resolverService.GetProductAsync },
                { "availabilities", resolverService.GetAvailabilitiesAsync },
                { "availability", resolverService.GetAvailabilityAsync },
                { "carts", resolverService.GetCartAsync },
            };
        }
Exemple #3
0
        public CoolStoreSchema(IHttpContextAccessor httpContext, ICoolStoreResolverService resolverService)
        {
            _httpContext = httpContext;
            var schema        = IdlSchema.CreateAsync().Result;
            var schemaBuilder = new SchemaBuilder(schema);
            var resolvers     = new CoolStoreResolvers(resolverService);

            CoolStore = SchemaTools.MakeExecutableSchemaWithIntrospection(
                schemaBuilder,
                resolvers,
                resolvers, new Dictionary <string, CreateDirectiveVisitor>
            {
                ["authorize"] = AuthorizeVisitor()
            });
        }
        public CoolStoreResolvers(ICoolStoreResolverService resolverService)
        {
            this["Product"] = new FieldResolverMap
            {
                { "id", PropertyOf <CatalogProductDto>(m => m.Id) },
                { "name", PropertyOf <CatalogProductDto>(m => m.Name) },
                { "price", PropertyOf <CatalogProductDto>(m => m.Price) },
                { "imageUrl", PropertyOf <CatalogProductDto>(m => m.ImageUrl) },
                { "desc", PropertyOf <CatalogProductDto>(m => m.Desc) }
            };

            this["Cart"] = new FieldResolverMap
            {
                { "id", PropertyOf <CartDto>(m => m.Id) },
                { "cartItemTotal", PropertyOf <CartDto>(m => m.CartItemTotal) },
                { "cartItemPromoSavings", PropertyOf <CartDto>(m => m.CartItemPromoSavings) },
                { "shippingTotal", PropertyOf <CartDto>(m => m.ShippingTotal) },
                { "shippingPromoSavings", PropertyOf <CartDto>(m => m.ShippingPromoSavings) },
                { "cartTotal", PropertyOf <CartDto>(m => m.CartTotal) },
                { "isCheckOut", PropertyOf <CartDto>(m => m.IsCheckOut) },
                { "items", PropertyOf <CartDto>(m => m.Items) }
            };

            this["CartItem"] = new FieldResolverMap
            {
                { "productId", PropertyOf <CartItemDto>(m => m.ProductId) },
                { "productName", PropertyOf <CartItemDto>(m => m.ProductName) },
                { "quantity", PropertyOf <CartItemDto>(m => m.Quantity) },
                { "price", PropertyOf <CartItemDto>(m => m.Price) },
                { "promoSavings", PropertyOf <CartItemDto>(m => m.PromoSavings) }
            };

            this["Inventory"] = new FieldResolverMap
            {
                { "id", PropertyOf <InventoryDto>(m => m.Id) },
                { "location", PropertyOf <InventoryDto>(m => m.Location) },
                { "quantity", PropertyOf <InventoryDto>(m => m.Quantity) },
                { "link", PropertyOf <InventoryDto>(m => m.Link) }
            };

            this["Rating"] = new FieldResolverMap
            {
                { "id", PropertyOf <RatingDto>(m => m.Id) },
                { "productId", PropertyOf <RatingDto>(m => m.ProductId) },
                { "userId", PropertyOf <RatingDto>(m => m.UserId) },
                { "cost", PropertyOf <RatingDto>(m => m.Cost) }
            };

            this["Review"] = new FieldResolverMap
            {
                { "id", PropertyOf <ReviewDto>(m => m.Id) },
                { "content", PropertyOf <ReviewDto>(m => m.Content) },
                { "authorId", PropertyOf <ReviewDto>(m => m.AuthorId) },
                { "authorName", PropertyOf <ReviewDto>(m => m.AuthorName) },
                { "productId", PropertyOf <ReviewDto>(m => m.ProductId) },
                { "productName", PropertyOf <ReviewDto>(m => m.ProductName) }
            };

            this["Query"] = new FieldResolverMap
            {
                { "products", resolverService.GetProductsAsync },
                { "product", resolverService.GetProductAsync },
                { "carts", resolverService.GetCartAsync },
                { "availabilities", resolverService.GetAvailabilitiesAsync },
                { "availability", resolverService.GetAvailabilityAsync },
                { "ratings", resolverService.GetRatingsAsync },
                { "rating", resolverService.GetRatingAsync },
                { "reviews", resolverService.GetReviewsAsync }
            };

            this["Mutation"] = new FieldResolverMap
            {
                { "createProduct", resolverService.CreateProductAsync },
                { "insertItemToNewCart", resolverService.InsertItemToNewCartAsync },
                { "updateItemInCart", resolverService.UpdateItemInCartAsync },
                { "deleteItem", resolverService.DeleteItemAsync },
                { "checkout", resolverService.CheckoutAsync },
                { "createRating", resolverService.CreateRatingAsync },
                { "updateRating", resolverService.UpdateRatingAsync },
                { "createReview", resolverService.CreateReviewAsync },
                { "editReview", resolverService.EditReviewAsync },
                { "deleteReview", resolverService.DeleteReviewAsync }
            };
        }