-
-
Notifications
You must be signed in to change notification settings - Fork 803
Allow for conditional warmup tasks based on IOptions #9086
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
...olate/Adapters/src/Adapters.OpenApi/Extensions/OpenApiRequestExecutorBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using HotChocolate.Execution.Configuration; | ||
| using HotChocolate.Adapters.OpenApi; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| public static class OpenApiRequestExecutorBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds an OpenAPI definition storage to the gateway. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The <see cref="IRequestExecutorBuilder"/>. | ||
| /// </param> | ||
| /// <param name="storage"> | ||
| /// The OpenAPI definition storage instance. | ||
| /// </param> | ||
| /// <param name="skipIf"> | ||
| /// A function that is called to determine if the storage should be registered or not. | ||
| /// If <c>true</c> is returned, the storage will not be registered. | ||
| /// </param> | ||
| /// <returns> | ||
| /// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// The <paramref name="builder"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// The <paramref name="storage"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// The <see cref="IServiceProvider"/> passed to the <paramref name="skipIf"/> | ||
| /// is for the application services. | ||
| /// </remarks> | ||
| public static IRequestExecutorBuilder AddOpenApiDefinitionStorage( | ||
| this IRequestExecutorBuilder builder, | ||
| IOpenApiDefinitionStorage storage, | ||
| Func<IServiceProvider, bool>? skipIf = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentNullException.ThrowIfNull(storage); | ||
|
|
||
| builder.AddOpenApiDefinitionStorageCore(skipIf); | ||
|
|
||
| builder.Services.AddKeyedSingleton(builder.Name, storage); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds an OpenAPI definition storage to the gateway. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The <see cref="IRequestExecutorBuilder"/>. | ||
| /// </param> | ||
| /// <param name="skipIf"> | ||
| /// A function that is called to determine if the storage should be registered or not. | ||
| /// If <c>true</c> is returned, the storage will not be registered. | ||
| /// </param> | ||
| /// <typeparam name="T"> | ||
| /// The type of the OpenAPI definition storage. | ||
| /// </typeparam> | ||
| /// <returns> | ||
| /// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// The <paramref name="builder"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// The <typeparamref name="T"/> will be activated with the <see cref="IServiceProvider"/> of the schema services. | ||
| /// If your <typeparamref name="T"/> needs to access application services you need to | ||
| /// make the services available in the schema services via <see cref="RequestExecutorBuilderExtensions.AddApplicationService"/>. | ||
| /// <br /> | ||
| /// The <see cref="IServiceProvider"/> passed to the <paramref name="skipIf"/> | ||
| /// is for the application services. | ||
| /// </remarks> | ||
| public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< | ||
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( | ||
| this IRequestExecutorBuilder builder, | ||
| Func<IServiceProvider, bool>? skipIf = null) | ||
| where T : class, IOpenApiDefinitionStorage | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| builder.AddOpenApiDefinitionStorageCore(skipIf); | ||
|
|
||
| builder.Services.AddKeyedSingleton<IOpenApiDefinitionStorage, T>(builder.Name); | ||
|
tobias-tengler marked this conversation as resolved.
|
||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds an OpenAPI definition storage to the gateway. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The <see cref="IRequestExecutorBuilder"/>. | ||
| /// </param> | ||
| /// <param name="factory"> | ||
| /// The factory to create the OpenAPI definition storage. | ||
| /// </param> | ||
| /// <param name="skipIf"> | ||
| /// A function that is called to determine if the storage should be registered or not. | ||
| /// If <c>true</c> is returned, the storage will not be registered. | ||
| /// </param> | ||
| /// <typeparam name="T"> | ||
| /// The type of the OpenAPI definition storage. | ||
| /// </typeparam> | ||
| /// <returns> | ||
| /// Returns the <see cref="IRequestExecutorBuilder"/> so that configuration can be chained. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// The <paramref name="builder"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// The <paramref name="factory"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <remarks> | ||
| /// The <see cref="IServiceProvider"/> passed to the <paramref name="factory"/> | ||
| /// is for the schema services. If you need to access application services | ||
| /// you need to either make the services available in the schema services | ||
| /// via <see cref="RequestExecutorBuilderExtensions.AddApplicationService"/> or use | ||
| /// <see cref="ExecutionServiceProviderExtensions.GetRootServiceProvider(IServiceProvider)"/> | ||
| /// to access the application services from within the schema service provider. | ||
| /// <br /> | ||
| /// The <see cref="IServiceProvider"/> passed to the <paramref name="skipIf"/> | ||
| /// is for the application services. | ||
|
tobias-tengler marked this conversation as resolved.
|
||
| /// </remarks> | ||
| public static IRequestExecutorBuilder AddOpenApiDefinitionStorage< | ||
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( | ||
| this IRequestExecutorBuilder builder, | ||
| Func<IServiceProvider, T> factory, | ||
| Func<IServiceProvider, bool>? skipIf = null) | ||
| where T : class, IOpenApiDefinitionStorage | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentNullException.ThrowIfNull(factory); | ||
|
|
||
| builder.AddOpenApiDefinitionStorageCore(skipIf); | ||
|
|
||
| builder.Services.AddKeyedSingleton<IOpenApiDefinitionStorage, T>( | ||
| builder.Name, | ||
| (sp, _) => factory(sp)); | ||
|
tobias-tengler marked this conversation as resolved.
|
||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static void AddOpenApiDefinitionStorageCore( | ||
| this IRequestExecutorBuilder builder, | ||
| Func<IServiceProvider, bool>? skipIf) | ||
| { | ||
| var schemaName = builder.Name; | ||
|
|
||
| builder.Services.AddOpenApiServices(schemaName); | ||
| builder.Services.AddOpenApiAspNetCoreServices(schemaName); | ||
|
|
||
| builder.ConfigureSchemaServices((_, schemaServices) => | ||
| { | ||
| schemaServices.TryAddSingleton<IOpenApiResultFormatter, OpenApiResultFormatter>(); | ||
| schemaServices.AddOpenApiSchemaServices(); | ||
| }); | ||
|
|
||
| builder.AddWarmupTask( | ||
| factory: schemaServices => | ||
| { | ||
| var registry = schemaServices.GetRootServiceProvider() | ||
| .GetRequiredKeyedService<OpenApiDefinitionRegistry>(schemaName); | ||
|
|
||
| return new OpenApiWarmupTask(registry); | ||
| }, | ||
| skipIf: skipIf); | ||
| } | ||
| } | ||
78 changes: 0 additions & 78 deletions
78
...HotChocolate/Adapters/src/Adapters.OpenApi/Extensions/RequestExecutorBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
...ocolate/Adapters/src/Fusion.Adapters.OpenApi/Extensions/FusionGatewayBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.