public static void Seed(this GraphQLDBContext dbContext) { if (!dbContext.Products.Any()) { dbContext.Products.AddRange(DumpProducts()); dbContext.SaveChanges(); } }
// 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"); } }); }
public ProductRepository(GraphQLDBContext context) { _context = context; }