Skip to content

Commit 00f0455

Browse files
authored
Remove obsolete methods (#693)
1 parent 26dd21a commit 00f0455

26 files changed

+95
-554
lines changed

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,33 @@ More information about ASP.NET Core routing [here](https://docs.microsoft.com/en
124124
```c#
125125
public void ConfigureServices(IServiceCollection services)
126126
{
127-
// Add GraphQL services and configure options
127+
// Add your custom services
128128
services
129-
.AddSingleton<IChat, Chat>()
130-
.AddSingleton<ChatSchema>();
129+
.AddSingleton<IChat, Chat>();
131130

132-
MicrosoftDI.GraphQLBuilderExtensions.AddGraphQL(services)
131+
// Add GraphQL services and configure options
132+
services.AddGraphQL(builder => builder
133133
.AddServer(true)
134-
.ConfigureExecution(options =>
134+
// For subscriptions support
135+
.AddDocumentExecuter<SubscriptionDocumentExecuter>()
136+
.AddSchema<ChatSchema>()
137+
.ConfigureExecutionOptions(options =>
135138
{
136139
options.EnableMetrics = Environment.IsDevelopment();
137140
var logger = options.RequestServices.GetRequiredService<ILogger<Startup>>();
138-
options.UnhandledExceptionDelegate = ctx => logger.LogError("{Error} occurred", ctx.OriginalException.Message);
141+
options.UnhandledExceptionDelegate = ctx =>
142+
{
143+
logger.LogError("{Error} occurred", ctx.OriginalException.Message);
144+
return Task.CompletedTask;
145+
};
139146
})
140147
// Add required services for GraphQL request/response de/serialization
141148
.AddSystemTextJson() // For .NET Core 3+
142149
.AddNewtonsoftJson() // For everything else
143150
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
144151
.AddWebSockets() // Add required services for web socket support
145152
.AddDataLoader() // Add required services for DataLoader support
146-
.AddGraphTypes(typeof(ChatSchema).Assembly) // Add all IGraphType implementors in assembly which ChatSchema exists
153+
.AddGraphTypes(typeof(ChatSchema).Assembly)); // Add all IGraphType implementors in assembly which ChatSchema exists
147154
}
148155

149156
public void Configure(IApplicationBuilder app)
@@ -176,19 +183,26 @@ public void Configure(IApplicationBuilder app)
176183
```c#
177184
public void ConfigureServices(IServiceCollection services)
178185
{
179-
// Add GraphQL services and configure options
186+
// Add your custom services
180187
services
181188
.AddRouting()
182-
.AddSingleton<IChat, Chat>()
183-
.AddSingleton<ChatSchema>();
189+
.AddSingleton<IChat, Chat>();
184190

185-
MicrosoftDI.GraphQLBuilderExtensions.AddGraphQL(services)
191+
// Add GraphQL services and configure options
192+
services.AddGraphQL(builder => builder
186193
.AddServer(true)
187-
.ConfigureExecution(options =>
194+
// For subscriptions support
195+
.AddDocumentExecuter<SubscriptionDocumentExecuter>()
196+
.AddSchema<ChatSchema>()
197+
.ConfigureExecutionOptions(options =>
188198
{
189199
options.EnableMetrics = Environment.IsDevelopment();
190200
var logger = options.RequestServices.GetRequiredService<ILogger<Startup>>();
191-
options.UnhandledExceptionDelegate = ctx => logger.LogError("{Error} occurred", ctx.OriginalException.Message);
201+
options.UnhandledExceptionDelegate = ctx =>
202+
{
203+
logger.LogError("{Error} occurred", ctx.OriginalException.Message);
204+
return Task.CompletedTask;
205+
};
192206
})
193207
// It is required when both GraphQL HTTP and GraphQL WebSockets middlewares are mapped to the same endpoint (by default 'graphql').
194208
.AddDefaultEndpointSelectorPolicy()
@@ -198,7 +212,7 @@ public void ConfigureServices(IServiceCollection services)
198212
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
199213
.AddWebSockets() // Add required services for web socket support
200214
.AddDataLoader() // Add required services for DataLoader support
201-
.AddGraphTypes(typeof(ChatSchema).Assembly); // Add all IGraphType implementors in assembly which ChatSchema exists
215+
.AddGraphTypes(typeof(ChatSchema).Assembly)); // Add all IGraphType implementors in assembly which ChatSchema exists
202216
}
203217

204218
public void Configure(IApplicationBuilder app)

samples/Samples.Server/Samples.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
1313
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
14-
<PackageReference Include="GraphQL.MicrosoftDI" Version="4.6.1" />
14+
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-414" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

samples/Samples.Server/Startup.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System.Collections.Generic;
2+
using System.Threading.Tasks;
23
using GraphQL.DataLoader;
34
using GraphQL.Execution;
4-
using System.Threading.Tasks;
5+
using GraphQL.MicrosoftDI;
56
using GraphQL.Samples.Schemas.Chat;
67
using GraphQL.Server;
78
using GraphQL.Server.Authorization.AspNetCore;
@@ -33,11 +34,14 @@ public Startup(IConfiguration configuration, IWebHostEnvironment environment)
3334
// This method gets called by the runtime. Use this method to add services to the container.
3435
public void ConfigureServices(IServiceCollection services)
3536
{
36-
services.AddSingleton<IChat, Chat>();
37-
services.AddTransient<IAuthorizationErrorMessageBuilder, DefaultAuthorizationErrorMessageBuilder>(); // required by CustomErrorInfoProvider
37+
services
38+
.AddSingleton<IChat, Chat>()
39+
.Configure<ErrorInfoProviderOptions>(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
40+
.AddTransient<IAuthorizationErrorMessageBuilder, DefaultAuthorizationErrorMessageBuilder>(); // required by CustomErrorInfoProvider
3841

39-
MicrosoftDI.GraphQLBuilderExtensions.AddGraphQL(services)
42+
services.AddGraphQL(builder => builder
4043
.AddServer(true)
44+
.AddDocumentExecuter<SubscriptionDocumentExecuter>()
4145
.AddSchema<ChatSchema>()
4246
.ConfigureExecutionOptions(options =>
4347
{
@@ -51,10 +55,9 @@ public void ConfigureServices(IServiceCollection services)
5155
})
5256
.AddSystemTextJson()
5357
.AddErrorInfoProvider<CustomErrorInfoProvider>()
54-
.Configure<ErrorInfoProviderOptions>(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
5558
.AddWebSockets()
5659
.AddDataLoader()
57-
.AddGraphTypes(typeof(ChatSchema).Assembly);
60+
.AddGraphTypes(typeof(ChatSchema).Assembly));
5861
}
5962

6063
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

samples/Samples.Server/StartupWithRouting.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Hosting;
1616
using Microsoft.Extensions.Logging;
17+
using GraphQL.MicrosoftDI;
1718

1819
namespace GraphQL.Samples.Server
1920
{
@@ -32,11 +33,14 @@ public StartupWithRouting(IConfiguration configuration, IWebHostEnvironment envi
3233
// This method gets called by the runtime. Use this method to add services to the container.
3334
public void ConfigureServices(IServiceCollection services)
3435
{
35-
services.AddRouting();
36-
services.AddSingleton<IChat, Chat>();
36+
services
37+
.AddRouting()
38+
.AddSingleton<IChat, Chat>()
39+
.Configure<ErrorInfoProviderOptions>(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment());
3740

38-
MicrosoftDI.GraphQLBuilderExtensions.AddGraphQL(services)
41+
services.AddGraphQL(builder => builder
3942
.AddServer(true)
43+
.AddDocumentExecuter<SubscriptionDocumentExecuter>()
4044
.AddSchema<ChatSchema>()
4145
.ConfigureExecutionOptions(options =>
4246
{
@@ -51,10 +55,9 @@ public void ConfigureServices(IServiceCollection services)
5155
.AddDefaultEndpointSelectorPolicy()
5256
.AddSystemTextJson()
5357
.AddErrorInfoProvider<CustomErrorInfoProvider>()
54-
.Configure<ErrorInfoProviderOptions>(opt => opt.ExposeExceptionStackTrace = Environment.IsDevelopment())
5558
.AddWebSockets()
5659
.AddDataLoader()
57-
.AddGraphTypes(typeof(ChatSchema).Assembly);
60+
.AddGraphTypes(typeof(ChatSchema).Assembly));
5861
}
5962

6063
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

src/All/All.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<ProjectReference Include="..\Ui.Playground\Ui.Playground.csproj" />
2222
<ProjectReference Include="..\Ui.Voyager\Ui.Voyager.csproj" />
2323

24-
<PackageReference Include="GraphQL.MemoryCache" Version="5.0.0-preview-397" />
25-
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-397" />
26-
<PackageReference Include="GraphQL.SystemReactive" Version="5.0.0-preview-397" />
24+
<PackageReference Include="GraphQL.MemoryCache" Version="5.0.0-preview-414" />
25+
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-414" />
26+
<PackageReference Include="GraphQL.SystemReactive" Version="5.0.0-preview-414" />
2727
</ItemGroup>
2828

2929
</Project>

src/Authorization.AspNetCore/GraphQLBuilderAuthorizationExtensions.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#nullable enable
22

33
using System;
4+
using GraphQL.DI;
45
using GraphQL.Server.Authorization.AspNetCore;
5-
using GraphQL.Validation;
66
using Microsoft.AspNetCore.Authorization;
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -16,36 +16,7 @@ public static class GraphQLBuilderAuthorizationExtensions
1616
/// </summary>
1717
/// <param name="builder">The GraphQL builder.</param>
1818
/// <returns>Reference to the passed <paramref name="builder"/>.</returns>
19-
[Obsolete]
2019
public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder builder)
21-
=> builder.AddGraphQLAuthorization(options => { });
22-
23-
/// <summary>
24-
/// Adds the GraphQL authorization.
25-
/// </summary>
26-
/// <param name="builder">The GraphQL builder.</param>
27-
/// <param name="options">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param>
28-
/// <returns>Reference to the passed <paramref name="builder"/>.</returns>
29-
[Obsolete]
30-
public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder builder, Action<AuthorizationOptions> options)
31-
{
32-
builder.Services.TryAddTransient<IClaimsPrincipalAccessor, DefaultClaimsPrincipalAccessor>();
33-
builder.Services.TryAddTransient<IAuthorizationErrorMessageBuilder, DefaultAuthorizationErrorMessageBuilder>();
34-
35-
builder.Services
36-
.AddHttpContextAccessor()
37-
.AddTransient<IValidationRule, AuthorizationValidationRule>()
38-
.AddAuthorizationCore(options);
39-
40-
return builder;
41-
}
42-
43-
/// <summary>
44-
/// Adds the GraphQL authorization.
45-
/// </summary>
46-
/// <param name="builder">The GraphQL builder.</param>
47-
/// <returns>Reference to the passed <paramref name="builder"/>.</returns>
48-
public static DI.IGraphQLBuilder AddGraphQLAuthorization(this DI.IGraphQLBuilder builder)
4920
=> builder.AddGraphQLAuthorization(_ => { });
5021

5122
/// <summary>
@@ -54,9 +25,9 @@ public static DI.IGraphQLBuilder AddGraphQLAuthorization(this DI.IGraphQLBuilder
5425
/// <param name="builder">The GraphQL builder.</param>
5526
/// <param name="configure">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param>
5627
/// <returns>Reference to the passed <paramref name="builder"/>.</returns>
57-
public static DI.IGraphQLBuilder AddGraphQLAuthorization(this DI.IGraphQLBuilder builder, Action<AuthorizationOptions>? configure)
28+
public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder builder, Action<AuthorizationOptions>? configure)
5829
{
59-
if (!(builder is IServiceCollection services))
30+
if (builder.Services is not IServiceCollection services)
6031
throw new NotSupportedException("This method only supports the MicrosoftDI implementation of IGraphQLBuilder.");
6132

6233
services.TryAddTransient<IClaimsPrincipalAccessor, DefaultClaimsPrincipalAccessor>();

src/Core/Core.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<!--TODO: remove SystemReactive in v6 -->
12-
<PackageReference Include="GraphQL.SystemReactive" Version="5.0.0-preview-397" />
13-
<PackageReference Include="GraphQL.DataLoader" Version="5.0.0-preview-397" />
11+
<PackageReference Include="GraphQL.DataLoader" Version="5.0.0-preview-414" />
1412
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.0" />
1513
</ItemGroup>
1614

0 commit comments

Comments
 (0)