예제 #1
0
 public static void Seed(this GraphQLDBContext dbContext)
 {
     if (!dbContext.Products.Any())
     {
         dbContext.Products.AddRange(DumpProducts());
         dbContext.SaveChanges();
     }
 }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GraphQLDBContext context)
        {
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            // app.UseHttpsRedirection();

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseWebSockets();
            app.UseGraphQLWebSockets <ProductSchema>();

            // add http for Schema at default url /graphql
            app.UseGraphQL <ProductSchema>();

            // use graphql-playground at default url /ui/playground
            app.UseGraphQLPlayground();

            context.Seed();

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
예제 #3
0
 public ProductRepository(GraphQLDBContext context)
 {
     _context = context;
 }