예제 #1
0
 public static IServiceCollection AddGraphQLSchema(
     this IServiceCollection services,
     ISchemaBuilder builder)
 {
     return(services.AddSingleton <ISchema>(
                sp => builder.AddServices(sp).Create())
            .AddSingleton <IIdSerializer, IdSerializer>());
 }
예제 #2
0
 public static IServiceCollection AddGraphQLSchema(
     this IServiceCollection services,
     ISchemaBuilder schemaBuilder)
 {
     return(services.AddSingleton(sp =>
                                  schemaBuilder
                                  .AddServices(sp)
                                  .Create()));
 }
 public static IServiceCollection AddGraphQLSchema(
     this IServiceCollection services,
     string name,
     ISchemaBuilder builder)
 {
     return(services
            .AddSingleton <INamedSchemaProvider>(sp => new NamedSchemaProvider(() => sp.GetServices <INamedSchema>()))
            .AddSingleton <INamedSchema>(
                sp => builder.AddServices(sp).Create().WithName(name))
            .AddSingleton <IIdSerializer, IdSerializer>());
 }
예제 #4
0
        public static IStitchingBuilder AddSchemaFromLocal(this IStitchingBuilder stitchingBuilder,
                                                           string serviceName, ISchemaBuilder schemaBuilder, IWebHostEnvironment env, IServiceCollection services)
        {
            var schemaName = $"AG_{serviceName}";

            stitchingBuilder.AddQueryExecutor(schemaName, sp => schemaBuilder.AddServices(sp).Create().MakeExecutable());

            // Add extensions (for types that get stitched in from this service)
            stitchingBuilder.AddExtensionsFromFileForService(serviceName, env);

            return(stitchingBuilder);
        }
        private async ValueTask <ISchema> CreateSchemaAsync(
            NameString schemaName,
            RequestExecutorSetup options,
            IServiceProvider serviceProvider,
            CancellationToken cancellationToken)
        {
            if (options.Schema is not null)
            {
                AssertSchemaNameValid(options.Schema, schemaName);
                return(options.Schema);
            }

            ISchemaBuilder schemaBuilder = options.SchemaBuilder ?? new SchemaBuilder();

            schemaBuilder.AddServices(serviceProvider);

            foreach (SchemaBuilderAction action in options.SchemaBuilderActions)
            {
                if (action.Action is { } configure)
                {
                    configure(serviceProvider, schemaBuilder);
                }

                if (action.AsyncAction is { } configureAsync)
                {
                    await configureAsync(serviceProvider, schemaBuilder, cancellationToken)
                    .ConfigureAwait(false);
                }
            }

            schemaBuilder.TryAddTypeInterceptor(new SetSchemaNameInterceptor(schemaName));

            ISchema schema = schemaBuilder.Create();

            AssertSchemaNameValid(schema, schemaName);
            return(schema);
        }