Exemplo n.º 1
0
        private async Task <IExecutionResult> ExecuteInternalAsync(
            QueryRequest request,
            CancellationToken cancellationToken = default)
        {
            QueryInfo queryInfo = null;
            Activity  activity  = QueryDiagnosticEvents.BeginExecute(
                Schema,
                request);

            try
            {
                queryInfo = GetOrCreateQuery(request.Query);
                if (queryInfo.ValidationResult.HasErrors)
                {
                    QueryDiagnosticEvents.ValidationError(
                        Schema,
                        request,
                        queryInfo.QueryDocument,
                        queryInfo.ValidationResult.Errors);

                    return(new QueryResult(queryInfo.ValidationResult.Errors));
                }

                return(await ExecuteOperationAsync(
                           request, queryInfo, cancellationToken));
            }
            finally
            {
                QueryDiagnosticEvents.EndExecute(
                    activity,
                    Schema,
                    request,
                    queryInfo?.QueryDocument);
            }
        }
        public async Task InvokeAsync(IQueryContext context)
        {
            Activity activity = QueryDiagnosticEvents.BeginExecute(
                context.Schema, context.Request);

            try
            {
                await _next(context);

                if (context.ValidationResult.HasErrors)
                {
                    QueryDiagnosticEvents.ValidationError(
                        context.Schema, context.Request,
                        context.Document, context.ValidationResult.Errors);
                }

                if (context.Exception != null)
                {
                    QueryDiagnosticEvents.QueryError(
                        context.Schema, context.Request,
                        context.Document, context.Exception);
                }
            }
            finally
            {
                QueryDiagnosticEvents.EndExecute(
                    activity, context.Schema,
                    context.Request, context.Document);
            }
        }
Exemplo n.º 3
0
        private async Task <IExecutionResult> ExecuteInternalAsync(
            QueryRequest queryRequest,
            QueryInfo queryInfo,
            CancellationToken cancellationToken)
        {
            OperationRequest operationRequest = null;

            try
            {
                OperationExecuter operationExecuter =
                    GetOrCreateOperationExecuter(
                        queryRequest, queryInfo.QueryDocument);

                operationRequest =
                    CreateOperationRequest(queryRequest);

                return(await operationExecuter.ExecuteAsync(
                           operationRequest, cancellationToken));
            }
            catch (QueryException ex)
            {
                QueryDiagnosticEvents.QueryError(
                    Schema,
                    queryRequest,
                    queryInfo.QueryDocument,
                    ex);

                return(new QueryResult(ex.Errors));
            }
            catch (Exception ex)
            {
                QueryDiagnosticEvents.QueryError(
                    Schema,
                    queryRequest,
                    queryInfo.QueryDocument,
                    ex);

                return(new QueryResult(CreateErrorFromException(ex)));
            }
            finally
            {
                operationRequest?.Session.Dispose();
            }
        }
Exemplo n.º 4
0
        public Task <IExecutionResult> ExecuteAsync(
            QueryRequest request,
            CancellationToken cancellationToken = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            QueryInfo queryInfo = null;
            Activity  activity  = QueryDiagnosticEvents.BeginExecute(
                Schema,
                request);

            try
            {
                queryInfo = GetOrCreateQuery(request.Query);
                if (queryInfo.ValidationResult.HasErrors)
                {
                    QueryDiagnosticEvents.ValidationError(
                        Schema,
                        request,
                        queryInfo.QueryDocument,
                        queryInfo.ValidationResult.Errors);

                    return(Task.FromResult <IExecutionResult>(
                               new QueryResult(queryInfo.ValidationResult.Errors)));
                }

                return(ExecuteInternalAsync(
                           request, queryInfo, cancellationToken));
            }
            finally
            {
                QueryDiagnosticEvents.EndExecute(
                    activity,
                    Schema,
                    request,
                    queryInfo?.QueryDocument);
            }
        }
        public async Task InvokeAsync(IQueryContext context)
        {
            DiagnosticListenerInitializer initializer = context.Services
                                                        .GetRequiredService <DiagnosticListenerInitializer>();

            initializer.Start();

            Activity activity = QueryDiagnosticEvents.BeginExecute(context);

            try
            {
                await _next(context).ConfigureAwait(false);

                if (context.Exception != null)
                {
                    QueryDiagnosticEvents.QueryError(context);
                }
            }
            finally
            {
                QueryDiagnosticEvents.EndExecute(activity, context);
            }
        }