protected async Task <IReadOnlyList <GraphQLRequest> > ReadRequestAsync( HttpContext context) { using (Stream stream = context.Request.Body) { IReadOnlyList <GraphQLRequest> batch = null; switch (ParseContentType(context.Request.ContentType)) { case AllowedContentType.Json: batch = await _requestHelper .ReadJsonRequestAsync( stream, context.GetCancellationToken()) .ConfigureAwait(false); break; case AllowedContentType.GraphQL: batch = await _requestHelper .ReadGraphQLQueryAsync( stream, context.GetCancellationToken()) .ConfigureAwait(false); break; default: throw new NotSupportedException(); } return(batch); } }
private async Task ExecuteQueryAsync( HttpContext context, IServiceProvider services, GraphQLRequest request) { IReadOnlyQueryRequest queryRequest = await BuildRequestAsync( context, services, QueryRequestBuilder.From(request)) .ConfigureAwait(false); IExecutionResult result = await _queryExecutor .ExecuteAsync(queryRequest, context.GetCancellationToken()) .ConfigureAwait(false); SetResponseHeaders( context.Response, _resultSerializer.ContentType); await _resultSerializer.SerializeAsync( result, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }
private async Task ExecuteOperationBatchAsync( HttpContext context, IServiceProvider services, GraphQLRequest request, IReadOnlyList <string> operationNames) { IReadOnlyList <IReadOnlyQueryRequest> requestBatch = await BuildBatchRequestAsync( context, services, request, operationNames) .ConfigureAwait(false); IResponseStream responseStream = await _batchExecutor .ExecuteAsync(requestBatch, context.GetCancellationToken()) .ConfigureAwait(false); SetResponseHeaders( context.Response, _streamSerializer.ContentType); await _streamSerializer.SerializeAsync( responseStream, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }
private async Task ExecuteQueryBatchAsync( HttpContext context, IServiceProvider services, IReadOnlyList <GraphQLRequest> batch) { IReadOnlyList <IReadOnlyQueryRequest> requestBatch = await BuildBatchRequestAsync(context, services, batch) .ConfigureAwait(false); SetResponseHeaders( context.Response, _streamSerializer.ContentType); var schemaName = await _schemaNameProvider(context).ConfigureAwait(false); var _batchExecutor = _batchExecutorProvider.GetExecutor(schemaName); IResponseStream responseStream = await _batchExecutor .ExecuteAsync(requestBatch, context.GetCancellationToken()) .ConfigureAwait(false); await _streamSerializer.SerializeAsync( responseStream, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }