-
Notifications
You must be signed in to change notification settings - Fork 161
Mark old IGraphQLBuilder extension methods obsolete and create new ones #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc14056
93a7829
e964eb3
cc0c7ab
bab5d80
9bb8d5b
3467c7e
7eb458e
014c99b
bfed979
ce8d62c
59d99bf
2ba24ce
6e4d190
6e793d8
2cbec77
8ca601f
81c2a39
a80f23d
e3c0b8b
ff555cf
bffb064
2373bc7
8286d77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
|
||
[Oo]bj/ | ||
[Bb]in/ | ||
|
||
*.received.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using GraphQL.Server.Authorization.AspNetCore; | ||
using GraphQL.Validation; | ||
|
@@ -14,6 +16,7 @@ public static class GraphQLBuilderAuthorizationExtensions | |
/// </summary> | ||
/// <param name="builder">The GraphQL builder.</param> | ||
/// <returns>Reference to the passed <paramref name="builder"/>.</returns> | ||
[Obsolete] | ||
public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder builder) | ||
=> builder.AddGraphQLAuthorization(options => { }); | ||
|
||
|
@@ -23,6 +26,7 @@ public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder build | |
/// <param name="builder">The GraphQL builder.</param> | ||
/// <param name="options">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param> | ||
/// <returns>Reference to the passed <paramref name="builder"/>.</returns> | ||
[Obsolete] | ||
public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder builder, Action<AuthorizationOptions> options) | ||
{ | ||
builder.Services.TryAddTransient<IClaimsPrincipalAccessor, DefaultClaimsPrincipalAccessor>(); | ||
|
@@ -33,5 +37,34 @@ public static IGraphQLBuilder AddGraphQLAuthorization(this IGraphQLBuilder build | |
|
||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the GraphQL authorization. | ||
/// </summary> | ||
/// <param name="builder">The GraphQL builder.</param> | ||
/// <returns>Reference to the passed <paramref name="builder"/>.</returns> | ||
public static DI.IGraphQLBuilder AddGraphQLAuthorization(this DI.IGraphQLBuilder builder) | ||
=> builder.AddGraphQLAuthorization(_ => { }); | ||
|
||
/// <summary> | ||
/// Adds the GraphQL authorization. | ||
/// </summary> | ||
/// <param name="builder">The GraphQL builder.</param> | ||
/// <param name="configure">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param> | ||
/// <returns>Reference to the passed <paramref name="builder"/>.</returns> | ||
public static DI.IGraphQLBuilder AddGraphQLAuthorization(this DI.IGraphQLBuilder builder, Action<AuthorizationOptions>? configure) | ||
{ | ||
if (!(builder is IServiceCollection services)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I see... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove
Then
+ remove
Then cast There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine (for v5 obviously). This is the 3rd option I mentioned. It will require a dependency on GraphQL.MicrosoftDI from the server project. Since it only works for Microsoft DI, the dependency makes sense.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But... then project needs a reference to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If OK I'll do a PR to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK.
I think we will be able to go without it. |
||
throw new NotSupportedException("This method only supports the MicrosoftDI implementation of IGraphQLBuilder."); | ||
services.TryAddTransient<IClaimsPrincipalAccessor, DefaultClaimsPrincipalAccessor>(); | ||
services.AddHttpContextAccessor(); | ||
if (configure != null) | ||
services.AddAuthorizationCore(configure); | ||
else | ||
services.AddAuthorizationCore(); | ||
builder.AddValidationRule<AuthorizationValidationRule>(); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GraphQL.Instrumentation; | ||
using GraphQL.Types; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace GraphQL.Server | ||
{ | ||
public class BasicGraphQLExecuter<TSchema> : IGraphQLExecuter<TSchema> | ||
where TSchema : ISchema | ||
{ | ||
public TSchema Schema { get; } | ||
|
||
private readonly IDocumentExecuter _documentExecuter; | ||
private readonly GraphQLOptions _options; | ||
|
||
public BasicGraphQLExecuter( | ||
sungam3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TSchema schema, | ||
IDocumentExecuter documentExecuter, | ||
IOptions<GraphQLOptions> options) | ||
{ | ||
Schema = schema; | ||
|
||
_documentExecuter = documentExecuter; | ||
_options = options.Value; | ||
} | ||
|
||
public virtual async Task<ExecutionResult> ExecuteAsync(string operationName, string query, Inputs variables, IDictionary<string, object> context, IServiceProvider requestServices, CancellationToken cancellationToken = default) | ||
{ | ||
var start = DateTime.UtcNow; | ||
|
||
var options = GetOptions(operationName, query, variables, context, requestServices, cancellationToken); | ||
var result = await _documentExecuter.ExecuteAsync(options); | ||
|
||
if (options.EnableMetrics) | ||
{ | ||
result.EnrichWithApolloTracing(start); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected virtual ExecutionOptions GetOptions(string operationName, string query, Inputs variables, IDictionary<string, object> context, IServiceProvider requestServices, CancellationToken cancellationToken) | ||
{ | ||
var opts = new ExecutionOptions | ||
{ | ||
Schema = Schema, | ||
OperationName = operationName, | ||
Query = query, | ||
Inputs = variables, | ||
UserContext = context, | ||
CancellationToken = cancellationToken, | ||
ComplexityConfiguration = _options.ComplexityConfiguration, | ||
EnableMetrics = _options.EnableMetrics, | ||
UnhandledExceptionDelegate = _options.UnhandledExceptionDelegate, | ||
MaxParallelExecutionCount = _options.MaxParallelExecutionCount, | ||
RequestServices = requestServices, | ||
}; | ||
|
||
return opts; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, this is a temporary inconvenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Although it is binary compatible it is probably not source compatible. There should be notes somewhere in here to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(That may happen when using GraphQL 4.6.1 regardless of the changes in this PR.)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use GraphQL.NET documentation site as a single place for projects' documentation. I would to make new sidebar section for server project.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graphql-dotnet/graphql-dotnet#2817