private async Task HandleRequestAsync(HttpContext context) { // first we need to get the request executor to be able to execute requests. IRequestExecutor requestExecutor = await GetExecutorAsync(context.RequestAborted); IHttpRequestInterceptor requestInterceptor = requestExecutor.GetRequestInterceptor(); IErrorHandler errorHandler = requestExecutor.GetErrorHandler(); HttpStatusCode? statusCode = null; IExecutionResult?result; try { // next we parse the GraphQL request. GraphQLRequest request = _requestParser.ReadParamsRequest(context.Request.Query); GraphQLServerOptions?options = context.GetGraphQLServerOptions(); result = await ExecuteSingleAsync( context, requestExecutor, requestInterceptor, request, options is null or { AllowedGetOperations : AllowedGetOperations.Query } ?_onlyQueries : null); }
private async Task HandleRequestAsync(HttpContext context) { // first we need to get the request executor to be able to execute requests. IRequestExecutor requestExecutor = await GetExecutorAsync(context.RequestAborted); IHttpRequestInterceptor requestInterceptor = requestExecutor.GetRequestInterceptor(); IErrorHandler errorHandler = requestExecutor.GetErrorHandler(); context.Items[WellKnownContextData.RequestExecutor] = requestExecutor; HttpStatusCode? statusCode = null; IExecutionResult?result; // next we parse the GraphQL request. GraphQLRequest request; using (_diagnosticEvents.ParseHttpRequest(context)) { try { request = _requestParser.ReadParamsRequest(context.Request.Query); } catch (GraphQLRequestException ex) { // A GraphQL request exception is thrown if the HTTP request body couldn't be // parsed. In this case we will return HTTP status code 400 and return a // GraphQL error result. statusCode = HttpStatusCode.BadRequest; IReadOnlyList <IError> errors = errorHandler.Handle(ex.Errors); result = QueryResultBuilder.CreateError(errors); _diagnosticEvents.ParserErrors(context, errors); goto HANDLE_RESULT; } catch (Exception ex) { statusCode = HttpStatusCode.InternalServerError; IError error = errorHandler.CreateUnexpectedError(ex).Build(); result = QueryResultBuilder.CreateError(error); _diagnosticEvents.HttpRequestError(context, error); goto HANDLE_RESULT; } } // after successfully parsing the request we now will attempt to execute the request. try { GraphQLServerOptions?options = context.GetGraphQLServerOptions(); result = await ExecuteSingleAsync( context, requestExecutor, requestInterceptor, _diagnosticEvents, request, options is null or { AllowedGetOperations : AllowedGetOperations.Query } ?_onlyQueries : null); }
private async Task HandleRequestAsync(HttpContext context) { // first we need to get the request executor to be able to execute requests. IRequestExecutor requestExecutor = await GetExecutorAsync(context.RequestAborted); IHttpRequestInterceptor requestInterceptor = requestExecutor.GetRequestInterceptor(); IErrorHandler errorHandler = requestExecutor.GetErrorHandler(); HttpStatusCode? statusCode = null; IExecutionResult?result; try { // next we parse the GraphQL request. GraphQLRequest request = _requestParser.ReadParamsRequest(context.Request.Query); result = await ExecuteSingleAsync( context, requestExecutor, requestInterceptor, request); } catch (GraphQLRequestException ex) { // A GraphQL request exception is thrown if the HTTP request body couldn't be // parsed. In this case we will return HTTP status code 400 and return a // GraphQL error result. statusCode = HttpStatusCode.BadRequest; result = QueryResultBuilder.CreateError(errorHandler.Handle(ex.Errors)); } catch (Exception ex) { statusCode = HttpStatusCode.InternalServerError; IError error = errorHandler.CreateUnexpectedError(ex).Build(); result = QueryResultBuilder.CreateError(error); } // in any case we will have a valid GraphQL result at this point that can be written // to the HTTP response stream. Debug.Assert(result is not null, "No GraphQL result was created."); await WriteResultAsync(context.Response, result, statusCode, context.RequestAborted); }