Beispiel #1
0
        /// <summary>
        /// Configures the services and settings for the schema using the supplied configuration function.
        /// </summary>
        public void ConfigureServices()
        {
            // create the builder to guide the rest of the setup operations
            _options = new SchemaOptions(typeof(TSchema));
            _schemaBuilder.TypeReferenceAdded += this.TypeReferenced_EventHandler;
            _options.TypeReferenceAdded       += this.TypeReferenced_EventHandler;

            _configureOptions?.Invoke(_options);

            // register global directives to the schema
            foreach (var type in Constants.GlobalDirectives)
            {
                _options.AddGraphType(type);
            }

            // add execution assembly for auto loading of graph types
            if (_options.AutoRegisterLocalGraphEntities)
            {
                var assembly = Assembly.GetEntryAssembly();
                _options.AddGraphAssembly(assembly);
            }

            // ensure some http processor is set
            if (_options.QueryHandler.HttpProcessorType == null)
            {
                if (_options.QueryHandler.AuthenticatedRequestsOnly)
                {
                    _options.QueryHandler.HttpProcessorType = typeof(SecureGraphQLHttpProcessor <TSchema>);
                }
                else
                {
                    _options.QueryHandler.HttpProcessorType = typeof(DefaultGraphQLHttpProcessor <TSchema>);
                }
            }

            // register the schema
            _serviceCollection.TryAddSingleton(this.BuildNewSchemaInstance);

            // setup default middleware for each required pipeline
            var queryPipelineHelper = new QueryExecutionPipelineHelper <TSchema>(_schemaBuilder.QueryExecutionPipeline);

            queryPipelineHelper.AddDefaultMiddlewareComponents(_options);

            var fieldPipelineHelper = new FieldExecutionPipelineHelper <TSchema>(_schemaBuilder.FieldExecutionPipeline);

            fieldPipelineHelper.AddDefaultMiddlewareComponents(_options);

            var authPipelineHelper = new FieldAuthorizationPipelineHelper <TSchema>(_schemaBuilder.FieldAuthorizationPipeline);

            authPipelineHelper.AddDefaultMiddlewareComponents(_options);

            // register the DI entries for each pipeline
            _serviceCollection.TryAddSingleton(this.CreatePipelineFactory(_schemaBuilder.FieldExecutionPipeline));
            _serviceCollection.TryAddSingleton(this.CreatePipelineFactory(_schemaBuilder.FieldAuthorizationPipeline));
            _serviceCollection.TryAddSingleton(this.CreatePipelineFactory(_schemaBuilder.QueryExecutionPipeline));

            this.RegisterEngineComponents();
        }