private async Task CreateFactoryOptionsAsync( RemoteSchemaDefinition schemaDefinition, IList <IConfigureRequestExecutorSetup> factoryOptions, CancellationToken cancellationToken) { await using ServiceProvider services = new ServiceCollection() .AddGraphQL(_schemaName) .AddRemoteSchema( schemaDefinition.Name, (sp, ct) => new ValueTask <RemoteSchemaDefinition>(schemaDefinition)) .Services .BuildServiceProvider(); IRequestExecutorOptionsMonitor optionsMonitor = services.GetRequiredService <IRequestExecutorOptionsMonitor>(); RequestExecutorSetup options = await optionsMonitor.GetAsync(schemaDefinition.Name, cancellationToken) .ConfigureAwait(false); factoryOptions.Add(new ConfigureRequestExecutorSetup(schemaDefinition.Name, options)); options = await optionsMonitor.GetAsync(_schemaName, cancellationToken) .ConfigureAwait(false); factoryOptions.Add(new ConfigureRequestExecutorSetup(_schemaName, options)); }
public async ValueTask <IEnumerable <INamedRequestExecutorFactoryOptions> > GetOptionsAsync( CancellationToken cancellationToken) { IEnumerable <RemoteSchemaDefinition> schemaDefinitions = await GetSchemaDefinitionsAsync(cancellationToken) .ConfigureAwait(false); var list = new List <INamedRequestExecutorFactoryOptions>(); var serviceCollection = new ServiceCollection(); IRequestExecutorBuilder builder = serviceCollection.AddGraphQL(); foreach (RemoteSchemaDefinition schemaDefinition in schemaDefinitions) { builder.AddRemoteSchema( schemaDefinition.Name, (sp, ct) => new ValueTask <RemoteSchemaDefinition>(schemaDefinition)); IServiceProvider services = serviceCollection.BuildServiceProvider(); IRequestExecutorOptionsMonitor optionsMonitor = services.GetRequiredService <IRequestExecutorOptionsMonitor>(); RequestExecutorFactoryOptions options = await optionsMonitor.GetAsync(schemaDefinition.Name, cancellationToken) .ConfigureAwait(false); // list.Add(new NamedRequestExecutorFactoryOptions(schemaDefinition.Name, options)); } return(list); }
public async ValueTask <IRequestExecutor> GetRequestExecutorNoLockAsync( NameString schemaName = default, CancellationToken cancellationToken = default) { schemaName = schemaName.HasValue ? schemaName : Schema.DefaultName; if (!_executors.TryGetValue(schemaName, out RegisteredExecutor? re)) { RequestExecutorFactoryOptions options = await _optionsMonitor.GetAsync(schemaName, cancellationToken) .ConfigureAwait(false); IServiceProvider schemaServices = await CreateSchemaServicesAsync(schemaName, options, cancellationToken) .ConfigureAwait(false); re = new RegisteredExecutor ( schemaServices.GetRequiredService <IRequestExecutor>(), schemaServices, schemaServices.GetRequiredService <IDiagnosticEvents>(), options ); foreach (OnRequestExecutorCreatedAction action in options.OnRequestExecutorCreated) { action.Action?.Invoke(re.Executor); if (action.AsyncAction is not null) { await action.AsyncAction.Invoke(re.Executor, cancellationToken) .ConfigureAwait(false); } } re.DiagnosticEvents.ExecutorCreated(schemaName, re.Executor); _executors.TryAdd(schemaName, re); } return(re.Executor); }