Skip to content

Instantly share code, notes, and snippets.

@JIOO-phoeNIX
Last active Jan 11, 2021
Embed
What would you like to do?
using GraphQLSampleApp.DataAccess;
using GraphQLSampleApp.DataAccess.DAO;
using GraphQLSampleApp.DataAccess.Entity;
using HotChocolate;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GraphQLSampleApp
{
public class Startup
{
private readonly string AllowedOrigin = "allowedOrigin";
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<SampleAppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SampleAppDbContext")));
services.AddInMemorySubscriptions();
services
.AddGraphQLServer()
.AddQueryType<Query>()
.AddMutationType<Mutation>()
.AddSubscriptionType<Subscription>();
services.AddScoped<EmployeeRepository, EmployeeRepository>();
services.AddScoped<DepartmentRepository, DepartmentRepository>();
services.AddCors(option => {
option.AddPolicy("allowedOrigin",
builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
);
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(AllowedOrigin);
app.UseWebSockets();
app
.UseRouting()
.UseEndpoints(endpoints =>
{
endpoints.MapGraphQL();
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment