/// <summary> /// Writes the given response directly to the output stream. /// </summary> /// <param name="result">The result.</param> /// <returns>Microsoft.AspNetCore.Mvc.IActionResult.</returns> protected virtual async Task WriteResponse(IGraphOperationResult result) { this.Response.ContentType = Constants.MediaTypes.JSON; if (_schema.Configuration.ResponseOptions.AppendServerHeader) { this.Response.Headers.Add(Constants.ServerInformation.SERVER_INFORMATION_HEADER, Constants.ServerInformation.ServerData); } var localWriter = new GraphQLHttpResponseWriter( result, _writer, this.ExposeMetrics, this.ExposeMetrics); await localWriter.WriteResultAsync(this.HttpContext).ConfigureAwait(false); }
public async Task GraphQlActionResult_NoResultProvided(bool exposeExceptions, string expectedText) { var(_, context) = this.CreateQueryArtifacts(); var httpContext = context; var response = httpContext.Response; var writer = new Mock <IGraphQueryResponseWriter>(); var result = new GraphQLHttpResponseWriter(null, writer.Object, false, exposeExceptions); await result.WriteResultAsync(httpContext); response.Body.Seek(0, SeekOrigin.Begin); string allText; using (var reader = new StreamReader(response.Body)) allText = reader.ReadToEnd(); Assert.AreEqual(expectedText, allText); Assert.AreEqual(500, response.StatusCode); }