예제 #1
0
        public void OnResolverError(
            string message,
            HotChocolateRequest request,
            IEnumerable <HotChocolateError> errors)
        {
            if (IsEnabled())
            {
                AttachmentId attachmentId = AttachmentId.NewId();

                IAttachment requestAttachment = AttachmentFactory
                                                .Create <HotChocolateRequestAttachment, HotChocolateRequest>(
                    attachmentId, nameof(request), request);

                HotChocolateErrorsAttachment errorAttachments = AttachmentFactory
                                                                .Create <HotChocolateErrorsAttachment, IEnumerable <HotChocolateError> >(
                    attachmentId, nameof(errors), errors);

                AttachmentDispatcher.Instance.Dispatch(
                    errorAttachments, requestAttachment);

                OnResolverError(
                    Application.Id, ActivityStack.Id,
                    attachmentId, message);
            }
        }
        /// <summary>
        /// Handles resolver error tracing.
        /// </summary>
        /// <param name="request">The request details.</param>
        /// <param name="error">The error details.</param>
        public void HandlesResolverError(
            HotChocolateRequest request,
            IError error)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            HotChocolateError[] formattedErrors =
            {
                new HotChocolateError
                {
                    Message   = error.Message,
                    Code      = error.Code,
                    Path      = error.Path?.ToList(),
                    Exception = error.Exception
                }
            };

            var message = error.Exception == null
                ? error.Message
                : error.Exception.Message;

            Log.OnResolverError(message, request, formattedErrors);
        }
        /// <summary>
        /// Handles validation error tracing.
        /// </summary>
        /// <param name="request">The request details.</param>
        /// <param name="errors">The error details.</param>
        public void HandleValidationErrors(
            HotChocolateRequest request,
            IReadOnlyList <IError> errors)
        {
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            if (errors.Count > 0)
            {
                var formattedErrors =
                    errors.Select(e =>
                                  new HotChocolateError
                {
                    Message   = e.Message,
                    Code      = e.Code,
                    Path      = e.Path?.ToList(),
                    Exception = e.Exception
                }).ToList();

                HotChocolateError firstError = formattedErrors[0];

                var message = firstError.Exception == null
                    ? firstError.Message
                    : firstError.Exception.Message;

                Log.OnValidationError(message, request, formattedErrors);
            }
        }
예제 #4
0
        /// <summary>
        /// Handles resolver error tracing.
        /// </summary>
        /// <param name="request">The request details.</param>
        /// <param name="errors">The error details.</param>
        public void HandlesResolverErrors(
            HotChocolateRequest request,
            IReadOnlyCollection <IError> errors)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            if (errors.Count > 0)
            {
                List <HotChocolateError> formattedErrors =
                    errors.Select(e =>
                                  new HotChocolateError
                {
                    Message   = e.Message,
                    Code      = e.Code,
                    Path      = e.Path,
                    Exception = e.Exception
                }).ToList();

                HotChocolateError firstError = formattedErrors[0];

                string message = firstError.Exception == null
                    ? firstError.Message
                    : firstError.Exception.Message;

                Log.OnResolverError(message, request, formattedErrors);
            }
        }
        public void BeginQueryExecute(IQueryContext context)
        {
            HotChocolateRequest request = _formatter.Serialize(context.Request);

            context.ContextData[nameof(HotChocolateRequest)] = request;

            HttpContext          httpContext = context.GetHttpContext();
            HotChocolateActivity activity    = HotChocolateActivity.Create(request);

            httpContext.Features.Set(activity);
        }
예제 #6
0
        public void Start(Guid activityId, HotChocolateRequest request)
        {
            if (IsEnabled())
            {
                AttachmentId attachmentId = AttachmentId.NewId();
                IAttachment  attachment   = AttachmentFactory
                                            .Create <HotChocolateRequestAttachment, HotChocolateRequest>(
                    attachmentId, nameof(request), request);

                AttachmentDispatcher.Instance.Dispatch(attachment);
                Start(Application.Id, activityId, attachmentId);
            }
        }
        public static HotChocolateActivity Create(HotChocolateRequest request)
        {
            var context = new HotChocolateActivity(request);

            if (context._relatedActivityId != Guid.Empty)
            {
                Log.BeginTransfer(context._relatedActivityId);
                Log.Start(context.Id, request);
                Log.EndTransfer(context.Id, context._relatedActivityId);
            }
            else
            {
                Log.Start(context.Id, request);
            }

            return(context);
        }
 private HotChocolateActivity(HotChocolateRequest request)
 {
     _relatedActivityId = ActivityStack.Id;
     _popWhenDispose    = ActivityStack.Push(Id);
     Request            = request;
 }