-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathStartup.cs
53 lines (46 loc) · 1.84 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Graphql.Extensions.FieldEnums.Types;
using GraphQL.Server;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using StarWars;
using StarWars.Types;
namespace Example
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<StarWarsData>();
services.AddSingleton<StarWarsQuery>();
services.AddSingleton<StarWarsMutation>();
services.AddSingleton<HumanType>();
services.AddSingleton<HumanInputType>();
services.AddSingleton<DroidType>();
services.AddSingleton<CharacterInterface>();
services.AddSingleton<EpisodeEnum>();
services.AddSingleton<ISchema, StarWarsSchema>();
services.AddSingleton(typeof(TypeFieldEnumerationWithoutLists<>), typeof(TypeFieldEnumerationWithoutLists<>));
services.AddLogging(builder => builder.AddConsole());
services.AddHttpContextAccessor();
services.AddGraphQL(options =>
{
options.EnableMetrics = true;
options.ExposeExceptions = true;
})
.AddNewtonsoftJson() // or use AddSystemTextJson for .NET Core 3+
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User });
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
// add http for Schema at default url /graphql
app.UseGraphQL<ISchema>();
// use graphql-playground at default url /ui/playground
app.UseGraphQLPlayground();
}
}
}