/// <summary> /// Initializes a new instance of the <see cref="GraphQLHttpResponseWriter" /> class. /// </summary> /// <param name="result">The graphql result to serialize.</param> /// <param name="documentWriter">The document writer to perform the serailization.</param> /// <param name="exposeMetrics">if set to <c>true</c> any metrics contained on the result will be exposed and sent to the requestor.</param> /// <param name="exposeExceptions">if set to <c>true</c> exceptions will be writen to the response stream; otherwise false.</param> public GraphQLHttpResponseWriter(IGraphOperationResult result, IGraphQueryResponseWriter documentWriter, bool exposeMetrics, bool exposeExceptions) { _result = result; _documentWriter = documentWriter; _options = new GraphQLResponseOptions() { ExposeExceptions = exposeExceptions, ExposeMetrics = exposeMetrics, }; }
private async Task <string> WriteResponse(IGraphQueryResponseWriter writer, IGraphOperationResult result, GraphQLResponseOptions options = null) { var stream = new MemoryStream(); options = options ?? new GraphQLResponseOptions() { ExposeExceptions = true, ExposeMetrics = true, }; await writer.WriteAsync(stream, result, options); stream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(stream)) return(reader.ReadToEnd()); }
/// <summary> /// Initializes a new instance of the <see cref="ApolloServerDataMessageConverter"/> class. /// </summary> /// <param name="schema">The schema.</param> /// <param name="responseWriter">The response writer.</param> public ApolloServerDataMessageConverter(ISchema schema, IGraphQueryResponseWriter responseWriter) { _responseWriter = Validation.ThrowIfNullOrReturn(responseWriter, nameof(responseWriter)); _schema = Validation.ThrowIfNullOrReturn(schema, nameof(schema)); }