Class DefaultHttpResponseFormatter
- Namespace
- HotChocolate.AspNetCore.Serialization
- Assembly
- HotChocolate.AspNetCore.dll
This represents the default implementation for the IHttpResponseFormatter that abides by the GraphQL over HTTP specification. https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md
public class DefaultHttpResponseFormatter : IHttpResponseFormatter
- Inheritance
-
DefaultHttpResponseFormatter
- Implements
- Inherited Members
Constructors
DefaultHttpResponseFormatter(HttpResponseFormatterOptions)
Creates a new instance of DefaultHttpResponseFormatter.
public DefaultHttpResponseFormatter(HttpResponseFormatterOptions options)
Parameters
optionsHttpResponseFormatterOptionsThe JSON result formatter options
DefaultHttpResponseFormatter(bool, JavaScriptEncoder?)
Creates a new instance of DefaultHttpResponseFormatter.
public DefaultHttpResponseFormatter(bool indented = false, JavaScriptEncoder? encoder = null)
Parameters
indentedboolDefines whether the underlying Utf8JsonWriter should pretty print the JSON which includes: indenting nested JSON tokens, adding new lines, and adding white space between property names and values. By default, the JSON is written without extra white spaces.
encoderJavaScriptEncoderGets or sets the encoder to use when escaping strings, or null to use the default encoder.
Methods
CreateRequestFlags(AcceptMediaType)
protected virtual GraphQLRequestFlags CreateRequestFlags(AcceptMediaType acceptMediaType)
Parameters
acceptMediaTypeAcceptMediaType
Returns
- GraphQLRequestFlags
CreateRequestFlags(AcceptMediaType[])
public GraphQLRequestFlags CreateRequestFlags(AcceptMediaType[] acceptMediaTypes)
Parameters
acceptMediaTypesAcceptMediaType[]
Returns
- GraphQLRequestFlags
FormatAsync(HttpResponse, IExecutionResult, AcceptMediaType[], HttpStatusCode?, CancellationToken)
public ValueTask FormatAsync(HttpResponse response, IExecutionResult result, AcceptMediaType[] acceptMediaTypes, HttpStatusCode? proposedStatusCode, CancellationToken cancellationToken)
Parameters
responseHttpResponseresultIExecutionResultacceptMediaTypesAcceptMediaType[]proposedStatusCodeHttpStatusCode?cancellationTokenCancellationToken
Returns
OnDetermineStatusCode(IQueryResult, FormatInfo, HttpStatusCode?)
Determines which status code shall be returned for this result.
protected virtual HttpStatusCode OnDetermineStatusCode(IQueryResult result, DefaultHttpResponseFormatter.FormatInfo format, HttpStatusCode? proposedStatusCode)
Parameters
resultIQueryResultThe HotChocolate.Execution.IQueryResult.
formatDefaultHttpResponseFormatter.FormatInfoProvides information about the transport format that is applied.
proposedStatusCodeHttpStatusCode?The proposed status code of the middleware.
Returns
- HttpStatusCode
Returns the HttpStatusCode that the formatter must use.
OnDetermineStatusCode(IResponseStream, FormatInfo, HttpStatusCode?)
Determines which status code shall be returned for this response stream.
protected virtual HttpStatusCode OnDetermineStatusCode(IResponseStream responseStream, DefaultHttpResponseFormatter.FormatInfo format, HttpStatusCode? proposedStatusCode)
Parameters
responseStreamIResponseStreamThe HotChocolate.Execution.IResponseStream.
formatDefaultHttpResponseFormatter.FormatInfoProvides information about the transport format that is applied.
proposedStatusCodeHttpStatusCode?The proposed status code of the middleware.
Returns
- HttpStatusCode
Returns the HttpStatusCode that the formatter must use.
OnWriteResponseHeaders(IQueryResult, FormatInfo, IHeaderDictionary)
Override to write response headers to the response message before the the formatter starts writing the response body.
protected virtual void OnWriteResponseHeaders(IQueryResult result, DefaultHttpResponseFormatter.FormatInfo format, IHeaderDictionary headers)
Parameters
resultIQueryResultThe HotChocolate.Execution.IQueryResult.
formatDefaultHttpResponseFormatter.FormatInfoProvides information about the transport format that is applied.
headersIHeaderDictionaryThe header dictionary.
OnWriteResponseHeaders(IResponseStream, FormatInfo, IHeaderDictionary)
Override to write response headers to the response message before the the formatter starts writing the response body.
protected virtual void OnWriteResponseHeaders(IResponseStream responseStream, DefaultHttpResponseFormatter.FormatInfo format, IHeaderDictionary headers)
Parameters
responseStreamIResponseStreamThe HotChocolate.Execution.IResponseStream.
formatDefaultHttpResponseFormatter.FormatInfoProvides information about the transport format that is applied.
headersIHeaderDictionaryThe header dictionary.