예제 #1
0
        public IGraphActionResult CustomMessageKeyClash()
        {
            var message = new GraphExecutionMessage(GraphMessageSeverity.Critical, "fail text", "fail code");

            message.MetaData.Add("severity", "gleam");
            return(this.Error(message));
        }
예제 #2
0
        public IGraphActionResult CustomMessage()
        {
            var message = new GraphExecutionMessage(GraphMessageSeverity.Critical, "fail text", "fail code");

            message.MetaData.Add("customKey1", "customValue1");
            return(this.Error(message));
        }
        /// <summary>
        /// Registers a validation error with the local message collection as a critical error. The validation
        /// message will automatically be appended with the appropriate message extensions to reference the error being validated.
        /// </summary>
        /// <param name="context">The validation context in scope.</param>
        /// <param name="message">The error message.</param>
        protected void ValidationError(DocumentConstructionContext context, string message)
        {
            var graphMessage = GraphExecutionMessage.FromValidationRule(
                this,
                message,
                context.ActiveNode.Location.AsOrigin());

            context.Messages.Add(graphMessage);
        }
예제 #4
0
        /// <summary>
        /// Returns an error indicating that an issue occured.
        /// </summary>
        /// <param name="severity">The severity of the message.</param>
        /// <param name="message">The human-friendly error message to assign ot the reported error in the graph result.</param>
        /// <param name="code">The error code to assign to the reported error in the graph result.</param>
        /// <param name="exception">An optional exception to be published if the query is configured to allow exposing exceptions.</param>
        /// <returns>IGraphActionResult.</returns>
        protected virtual IGraphActionResult Error(
            GraphMessageSeverity severity,
            string message,
            string code         = null,
            Exception exception = null)
        {
            var errorMessage = new GraphExecutionMessage(severity, message, code, exception: exception);

            return(this.Error(errorMessage));
        }
예제 #5
0
        /// <summary>
        /// Registers a validation error with the local message collection as a critical error. The validation
        /// message will automatically be appended with the appropriate message extensions to reference the error being validated.
        /// </summary>
        /// <param name="context">The validation context in scope.</param>
        /// <param name="message">The error message to apply.</param>
        /// <param name="exception">The exception to add to the message, if any.</param>
        protected void ValidationError(
            FieldValidationContext context,
            string message,
            Exception exception = null)
        {
            var graphMessage = GraphExecutionMessage.FromValidationRule(
                this,
                message,
                context.DataItem.FieldContext.Origin,
                exception);

            context.Messages.Add(graphMessage);
        }
예제 #6
0
        /// <summary>
        /// Attempts to create a qualified input argument for the supplied schema field.
        /// </summary>
        /// <param name="argument">The argument defined on schema that needs to have
        /// an input value created fro.</param>
        /// <returns>Task.</returns>
        public ArgumentGenerationResult CreateInputArgument(IGraphFieldArgument argument)
        {
            Validation.ThrowIfNull(argument, nameof(argument));

            if (!_suppliedArguments.ContainsKey(argument.Name))
            {
                return(new ArgumentGenerationResult(new ResolvedInputArgumentValue(argument.Name, argument.DefaultValue)));
            }

            var coreValue = _suppliedArguments[argument.Name].Value;
            var resolver  = _inputResolverGenerator.CreateResolver(coreValue.OwnerArgument.TypeExpression);

            if (this.ShouldDeferResolution(coreValue))
            {
                return(new ArgumentGenerationResult(new DeferredInputArgumentValue(coreValue, resolver)));
            }

            try
            {
                var data = resolver.Resolve(coreValue);
                return(new ArgumentGenerationResult(new ResolvedInputArgumentValue(coreValue.OwnerArgument.Name, data)));
            }
            catch (UnresolvedValueException svce)
            {
                var message = new GraphExecutionMessage(
                    GraphMessageSeverity.Critical,
                    svce.Message,
                    Constants.ErrorCodes.INVALID_ARGUMENT,
                    coreValue.OwnerArgument.Value.ValueNode.Location.AsOrigin(),
                    exception: svce.InnerException);

                return(new ArgumentGenerationResult(message));
            }
            catch (Exception ex)
            {
                var message = new GraphExecutionMessage(
                    GraphMessageSeverity.Critical,
                    "Invalid argument value.",
                    Constants.ErrorCodes.INVALID_ARGUMENT,
                    coreValue.OwnerArgument.Value.ValueNode.Location.AsOrigin(),
                    ex);

                return(new ArgumentGenerationResult(message));
            }
        }