public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, ITraceLogger traceLogger)
 {
     _documentBuilder    = documentBuilder ?? throw new ArgumentNullException(nameof(documentBuilder));
     _documentValidator  = documentValidator ?? throw new ArgumentNullException(nameof(documentValidator));
     _complexityAnalyzer = complexityAnalyzer ?? throw new ArgumentNullException(nameof(complexityAnalyzer));
     _traceLogger        = traceLogger ?? throw new ArgumentNullException(nameof(traceLogger));
 }
 public SubscriptionExecuter(
     IDocumentBuilder documentBuilder,
     IDocumentValidator documentValidator,
     IComplexityAnalyzer complexityAnalyzer)
     : base(documentBuilder, documentValidator, complexityAnalyzer)
 {
 }
Example #3
0
 public EventCapturer(IDocumentValidator documentValidator, IDocumentParser documentParser, IRequestPersister requestPersister, IUserProvider userProvider)
 {
     _documentValidator = documentValidator ?? throw new ArgumentException(nameof(documentValidator));
     _documentParser    = documentParser ?? throw new ArgumentException(nameof(documentParser));
     _requestPersister  = requestPersister ?? throw new ArgumentException(nameof(requestPersister));
     _userProvider      = userProvider ?? throw new ArgumentException(nameof(userProvider));
 }
Example #4
0
 public MasterdataCapturer(IDocumentValidator validator, IMasterdataParser masterdataParser, IUserProvider userProvider, IMasterdataRepository masterdataRepository)
 {
     _validator            = validator ?? throw new ArgumentNullException(nameof(validator));
     _masterdataParser     = masterdataParser ?? throw new ArgumentNullException(nameof(masterdataParser));
     _userProvider         = userProvider ?? throw new ArgumentNullException(nameof(userProvider));
     _masterdataRepository = masterdataRepository ?? throw new ArgumentNullException(nameof(masterdataRepository));
 }
        /// <summary>
        /// Initializes a new instance with the specified <see cref="IDocumentBuilder"/>,
        /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
        /// <see cref="IDocumentCache"/> and a set of <see cref="IConfigureExecutionOptions"/> instances.
        /// </summary>
        public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IExecutionStrategySelector executionStrategySelector, IEnumerable <IConfigureExecution> configurations, IEnumerable <IConfigureExecutionOptions> optionsConfigurations)
#pragma warning disable CS0618 // Type or member is obsolete
            : this(documentBuilder, documentValidator, complexityAnalyzer, documentCache, executionStrategySelector, configurations.Append(new ConfigureExecutionOptionsMapper(optionsConfigurations)))
#pragma warning restore CS0618 // Type or member is obsolete
        {
            // TODO: remove in v6
        }
 public QueryOnlyDocumentExecuter(
     IDocumentBuilder documentBuilder,
     IDocumentValidator documentValidator,
     IComplexityAnalyzer complexityAnalyzer)
     : base(documentBuilder, documentValidator, complexityAnalyzer)
 {
 }
 /// <summary>
 /// Initializes a new instance with specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
 /// and <see cref="IDocumentCache"/> instances.
 /// </summary>
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache)
 {
     _documentBuilder    = documentBuilder ?? throw new ArgumentNullException(nameof(documentBuilder));
     _documentValidator  = documentValidator ?? throw new ArgumentNullException(nameof(documentValidator));
     _complexityAnalyzer = complexityAnalyzer ?? throw new ArgumentNullException(nameof(complexityAnalyzer));
     _documentCache      = documentCache ?? throw new ArgumentNullException(nameof(documentCache));
 }
        private IReadOnlyList <HCError> ValidateQueryDocuments(ISchema schema)
        {
            var errors = new List <HCError>();

            try
            {
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddValidation();
                IDocumentValidator validator = serviceCollection.BuildServiceProvider()
                                               .GetService <IDocumentValidatorFactory>().CreateValidator();

                foreach (DocumentInfo documentInfo in _queries.Values)
                {
                    DocumentValidatorResult validationResult =
                        validator.Validate(schema, documentInfo.Document);

                    if (validationResult.HasErrors)
                    {
                        foreach (HCError error in validationResult.Errors)
                        {
                            errors.Add(HCErrorBuilder.FromError(error)
                                       .SetExtension("fileName", documentInfo.FileName)
                                       .SetExtension("document", documentInfo.Document)
                                       .Build());
                        }
                    }
                }
            }
            catch (GeneratorException ex)
            {
                errors.AddRange(ex.Errors);
            }

            return(errors);
        }
 /// <summary>
 /// Initializes a new instance with the specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
 /// <see cref="IDocumentCache"/> and a set of <see cref="IConfigureExecutionOptions"/> instances.
 /// </summary>
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IEnumerable <IConfigureExecutionOptions> configurations, IExecutionStrategySelector executionStrategySelector)
 {
     _documentBuilder           = documentBuilder ?? throw new ArgumentNullException(nameof(documentBuilder));
     _documentValidator         = documentValidator ?? throw new ArgumentNullException(nameof(documentValidator));
     _complexityAnalyzer        = complexityAnalyzer ?? throw new ArgumentNullException(nameof(complexityAnalyzer));
     _documentCache             = documentCache ?? throw new ArgumentNullException(nameof(documentCache));
     _configurations            = configurations?.ToArray();
     _executionStrategySelector = executionStrategySelector ?? throw new ArgumentNullException(nameof(executionStrategySelector));
 }
 /// <summary>
 /// Initializes a new instance with the specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
 /// <see cref="IDocumentCache"/> and a set of <see cref="IConfigureExecutionOptions"/> instances.
 /// </summary>
 private DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IExecutionStrategySelector executionStrategySelector, IEnumerable <IConfigureExecution> configurations)
 {
     // TODO: in v6 make this public
     _documentBuilder           = documentBuilder ?? throw new ArgumentNullException(nameof(documentBuilder));
     _documentValidator         = documentValidator ?? throw new ArgumentNullException(nameof(documentValidator));
     _complexityAnalyzer        = complexityAnalyzer ?? throw new ArgumentNullException(nameof(complexityAnalyzer));
     _documentCache             = documentCache ?? throw new ArgumentNullException(nameof(documentCache));
     _executionStrategySelector = executionStrategySelector ?? throw new ArgumentNullException(nameof(executionStrategySelector));
     _execution = BuildExecutionDelegate(configurations);
 }
 public ApolloTracingDocumentExecuter(
     IDocumentBuilder documentBuilder,
     IDocumentValidator documentValidator,
     IComplexityAnalyzer complexityAnalyzer,
     IDocumentCache documentCache,
     IEnumerable <IConfigureExecutionOptions> configureExecutionOptions,
     IExecutionStrategySelector executionStrategySelector)
     : base(documentBuilder, documentValidator, complexityAnalyzer, documentCache, configureExecutionOptions, executionStrategySelector)
 {
 }
 public DocumentValidationMiddleware(
     RequestDelegate next,
     IDiagnosticEvents diagnosticEvents,
     IDocumentValidator documentValidator)
 {
     _next = next ??
             throw new ArgumentNullException(nameof(next));
     _diagnosticEvents = diagnosticEvents ??
                         throw new ArgumentNullException(nameof(diagnosticEvents));
     _documentValidator = documentValidator ??
                          throw new ArgumentNullException(nameof(documentValidator));
 }
Example #13
0
        public void DocumentIsNull()
        {
            // arrange
            Schema             schema         = ValidationUtils.CreateSchema();
            IDocumentValidator queryValidator = CreateValidator();

            // act
            Action a = () => queryValidator.Validate(schema, null !);

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
Example #14
0
        private void ExpectValid(ISchema schema, IDocumentValidator validator, string sourceText)
        {
            // arrange
            schema ??= ValidationUtils.CreateSchema();
            validator ??= CreateValidator();
            DocumentNode query = Utf8GraphQLParser.Parse(sourceText);

            // act
            DocumentValidatorResult result = validator.Validate(schema, query);

            // assert
            Assert.Empty(result.Errors);
        }
Example #15
0
        public void SchemaIsNull()
        {
            // arrange
            Schema             schema         = ValidationUtils.CreateSchema();
            IDocumentValidator queryValidator = CreateValidator();

            // act
            // act
            Action a = () => queryValidator.Validate(null !,
                                                     new DocumentNode(null, new List <IDefinitionNode>()));

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
        public ValidateQueryMiddleware(
            QueryDelegate next,
            IDocumentValidatorFactory validatorFactory,
            Cache <DocumentValidatorResult> validatorCache,
            QueryExecutionDiagnostics diagnostics)
        {
            if (validatorFactory == null)
            {
                throw new ArgumentNullException(nameof(validatorFactory));
            }

            _next           = next ?? throw new ArgumentNullException(nameof(next));
            _validator      = validatorFactory.CreateValidator();
            _validatorCache = validatorCache ??
                              new Cache <DocumentValidatorResult>(Defaults.CacheSize);
            _diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics));
        }
Example #17
0
        public ValidationBenchmarks()
        {
            _services = new ServiceCollection()
                        .AddValidation().Services
                        .AddStarWarsRepositories()
                        .AddGraphQLSchema(b => b.AddStarWarsTypes())
                        .BuildServiceProvider();

            var factory = _services.GetRequiredService <IDocumentValidatorFactory>();

            _validator = factory.CreateValidator();

            _schema = _services.GetRequiredService <ISchema>();
            var resources = new ResourceHelper();

            _introspectionQuery = Utf8GraphQLParser.Parse(
                resources.GetResourceString("IntrospectionQuery.graphql"));
            _starWarsQuery = Utf8GraphQLParser.Parse(
                resources.GetResourceString("StarWarsQuery.graphql"));
        }
Example #18
0
        private static bool TryValidateRequest(
            ISchema schema,
            IReadOnlyList <GraphQLFile> executableFiles,
            Dictionary <ISyntaxNode, string> fileLookup,
            List <IError> errors)
        {
            IDocumentValidator validator = CreateDocumentValidator();

            DocumentNode            document         = MergeDocuments(executableFiles);
            DocumentValidatorResult validationResult = validator.Validate(schema, document);

            if (validationResult.HasErrors)
            {
                errors.AddRange(
                    validationResult.Errors.Select(
                        error => error.WithFileReference(fileLookup)));
                return(false);
            }

            return(true);
        }
Example #19
0
        public void DuplicatesWillBeIgnoredOnFieldMerging()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddStarWarsTypes()
                             .Create();

            DocumentNode document = Utf8GraphQLParser.Parse(
                FileResource.Open("InvalidIntrospectionQuery.graphql"));

            var originalOperation = ((OperationDefinitionNode)document.Definitions[0]);
            OperationDefinitionNode operationWithDuplicates = originalOperation.WithSelectionSet(
                originalOperation.SelectionSet.WithSelections(
                    new List <ISelectionNode>
            {
                originalOperation.SelectionSet.Selections[0],
                originalOperation.SelectionSet.Selections[0]
            }));

            document = document.WithDefinitions(
                new List <IDefinitionNode>(document.Definitions.Skip(1))
            {
                operationWithDuplicates
            });

            ServiceProvider services = new ServiceCollection()
                                       .AddValidation()
                                       .Services
                                       .BuildServiceProvider();

            IDocumentValidatorFactory factory   = services.GetRequiredService <IDocumentValidatorFactory>();
            IDocumentValidator        validator = factory.CreateValidator();

            // act
            DocumentValidatorResult result = validator.Validate(schema, document);

            // assert
            Assert.False(result.HasErrors);
        }
Example #20
0
        private void ExpectErrors(
            ISchema schema,
            IDocumentValidator validator,
            string sourceText,
            params Action <IError>[] elementInspectors)
        {
            // arrange
            schema ??= ValidationUtils.CreateSchema();
            validator ??= CreateValidator();
            DocumentNode query = Utf8GraphQLParser.Parse(sourceText);

            // act
            DocumentValidatorResult result = validator.Validate(schema, query);

            // assert
            Assert.NotEmpty(result.Errors);

            if (elementInspectors.Length > 0)
            {
                Assert.Collection(result.Errors, elementInspectors);
            }

            result.Errors.MatchSnapshot();
        }
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IEnumerable <IConfigureExecution>?configurations)
     : this(documentBuilder, documentValidator, complexityAnalyzer, documentCache)
 {
     _configurations = configurations;
 }
Example #22
0
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator)
 {
     _documentBuilder = documentBuilder;
     _documentValidator = documentValidator;
 }
 public RestoreCommandParser(IDocumentValidator validator)
 => this.validator = validator;
 /// <summary>
 /// Initializes a new instance with specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
 /// <see cref="IDocumentCache"/> and a set of <see cref="IConfigureExecutionOptions"/> instances.
 /// </summary>
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IEnumerable <IConfigureExecutionOptions> configurations)
     : this(documentBuilder, documentValidator, complexityAnalyzer, documentCache, configurations, new DefaultExecutionStrategySelector())
 {
 }
 public SubscriptionDocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IEnumerable <IConfigureExecution>?configurations)
     : base(documentBuilder, documentValidator, complexityAnalyzer, documentCache, configurations)
 {
 }
Example #26
0
 public EstablishmentValidator(IDocumentValidator documentValidator)
 {
     _documentValidator = documentValidator;
 }
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache, IEnumerable <IConfigureExecutionOptions> configurations, IExecutionStrategySelector executionStrategySelector)
     : this(documentBuilder, documentValidator, complexityAnalyzer, documentCache, executionStrategySelector, new IConfigureExecution[] { new ConfigureExecutionOptionsMapper(configurations) })
 {
 }
 /// <summary>
 /// Initializes a new instance with specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/>, <see cref="IComplexityAnalyzer"/>,
 /// and <see cref="IDocumentCache"/> instances.
 /// </summary>
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer, IDocumentCache documentCache)
     : this(documentBuilder, documentValidator, complexityAnalyzer, documentCache, new DefaultExecutionStrategySelector(), Array.Empty <IConfigureExecution>())
 {
 }
 /// <summary>
 /// Initializes a new instance with specified <see cref="IDocumentBuilder"/>,
 /// <see cref="IDocumentValidator"/> and <see cref="IComplexityAnalyzer"/> instances,
 /// and without document caching.
 /// </summary>
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer)
     : this(documentBuilder, documentValidator, complexityAnalyzer, DefaultDocumentCache.Instance)
 {
 }
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer)
 {
     _documentBuilder = documentBuilder;
     _documentValidator = documentValidator;
     _complexityAnalyzer = complexityAnalyzer;
 }
Example #31
0
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator, IComplexityAnalyzer complexityAnalyzer)
 {
     _documentBuilder    = documentBuilder;
     _documentValidator  = documentValidator;
     _complexityAnalyzer = complexityAnalyzer;
 }
Example #32
0
 public DocumentExecuter(IDocumentBuilder documentBuilder, IDocumentValidator documentValidator)
 {
     _documentBuilder   = documentBuilder;
     _documentValidator = documentValidator;
 }