Пример #1
0
        private static async Task ExecuteAsync(HttpContext context, ISchema schema)
        {
            GraphQLRequest request;

            using (var reader = new StreamReader(context.Request.Body))
                using (var jsonReader = new JsonTextReader(reader))
                {
                    var ser = new JsonSerializer();
                    request = ser.Deserialize <GraphQLRequest>(jsonReader);
                }

            var executer = new DocumentExecuter();
            var result   = await executer.ExecuteAsync(options =>
            {
                options.Schema = schema;
                if (request == null)
                {
                    return;
                }
                options.Query         = request.Query;
                options.OperationName = request.OperationName;
                options.Inputs        = request.Variables.ToInputs();
            });

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  =
                result.Errors?.Any() == true ? (int)HttpStatusCode.BadRequest : (int)HttpStatusCode.OK;

            var writer = new DocumentWriter();
            await writer.WriteAsync(context.Response.Body, result);
        }
Пример #2
0
 private static async Task WriteResultAsync(HttpContext httpContext, ExecutionResult executionResult)
 {
     httpContext.Response.ContentType = "application/json";
     httpContext.Response.StatusCode  =
         executionResult.Errors?.Any() == true ? (int)HttpStatusCode.BadRequest : (int)HttpStatusCode.OK;
     var writer = new DocumentWriter(true);
     await writer.WriteAsync(httpContext.Response.Body, executionResult);
 }
Пример #3
0
        public async Task WriteAsync <T>(Stream stream, T value,
                                         CancellationToken cancellationToken = default)
        {
            await using (var bufferStream = new FileBufferingWriteStream())
            {
                await documentWriter.WriteAsync(bufferStream, value, cancellationToken);

                await bufferStream.DrainBufferAsync(stream, cancellationToken);
            }
        }