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);
        }
Exemple #2
0
        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 RequestExecutorResolver(
     IRequestExecutorOptionsMonitor optionsMonitor,
     IServiceProvider serviceProvider)
 {
     _optionsMonitor = optionsMonitor ??
                       throw new ArgumentNullException(nameof(optionsMonitor));
     _applicationServices = serviceProvider ??
                            throw new ArgumentNullException(nameof(serviceProvider));
     _optionsMonitor.OnChange((options, name) => EvictRequestExecutor(name));
 }