/// <summary>
        /// Add required services for GraphQL
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureOptions"></param>
        /// <returns></returns>
        public static IGraphQLBuilder AddGraphQL(this IServiceCollection services, Action <GraphQLOptions> configureOptions)
        {
            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            var options = new GraphQLOptions();

            configureOptions(options);

            return(services.AddGraphQL(options));
        }
        /// <summary>
        /// Add required services for GraphQL
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IGraphQLBuilder AddGraphQL(this IServiceCollection services, GraphQLOptions options)
        {
            services.TryAddSingleton <IDocumentExecuter, DocumentExecuter>();
            services.AddTransient(typeof(IGraphQLExecuter <>), typeof(DefaultGraphQLExecuter <>));
            services.AddSingleton(Options.Create(options));

            services.TryAddSingleton <IDocumentWriter>(x =>
            {
                var jsonSerializerSettings = x.GetRequiredService <IOptions <JsonSerializerSettings> >();
                return(new DocumentWriter(Formatting.None, jsonSerializerSettings.Value));
            });

            return(new GraphQLBuilder(services));
        }
Ejemplo n.º 3
0
        public DefaultGraphQLExecuter(
            TSchema schema,
            IDocumentExecuter documentExecuter,
            IOptions <GraphQLOptions> options,
            IEnumerable <IDocumentExecutionListener> listeners,
            IEnumerable <IValidationRule> validationRules)
        {
            Schema = schema;

            _documentExecuter = documentExecuter;
            _options          = options.Value;
            _listeners        = listeners;
            _validationRules  = validationRules;
        }