private async Task <IOperationResult <T> > ParseInternalAsync( Stream stream, CancellationToken cancellationToken) { using (JsonDocument document = await JsonDocument.ParseAsync(stream) .ConfigureAwait(false)) { var builder = OperationResultBuilder.New <T>(); if (document.RootElement.TryGetProperty( _data, out JsonElement data)) { builder.SetData(ParserData(data)); } if (document.RootElement.TryGetProperty( _error, out JsonElement errors)) { // TODO : add error deserialization } if (document.RootElement.TryGetProperty( _extensions, out JsonElement extensions)) { // TODO : add extension deserialization } return(builder.Build()); } }
private async Task <IOperationResult <T> > ParseInternalAsync( Stream stream, CancellationToken cancellationToken) { using (JsonDocument document = await JsonDocument.ParseAsync(stream) .ConfigureAwait(false)) { var builder = OperationResultBuilder.New <T>(); if (document.RootElement.TryGetProperty( _data, out JsonElement data)) { builder.SetData(ParserData(data)); } if (document.RootElement.TryGetProperty( _error, out JsonElement errors)) { builder.AddErrors(ParseErrors(errors)); } if (TryParseExtensions( document.RootElement, out IReadOnlyDictionary <string, object?>?extensions)) { builder.AddExtensions(extensions !); } return(builder.Build()); } }
public async Task <IOperationResult> ExecuteAsync( IOperation operation, CancellationToken cancellationToken) { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } var resultBuilder = OperationResultBuilder.New(operation.ResultType); await ExecuteOperationAsync( operation, resultBuilder, cancellationToken) .ConfigureAwait(false); return(resultBuilder.Build()); }
public async Task <IOperationResult <T> > ExecuteAsync <T>( IOperation <T> operation, CancellationToken cancellationToken) where T : class { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } var resultBuilder = OperationResultBuilder.New <T>(); await ExecuteOperationAsync( operation, resultBuilder, cancellationToken) .ConfigureAwait(false); return(resultBuilder.Build()); }
private OperationMessage DeserializeSubscriptionResultMessage( GraphQLSocketMessage parsedMessage) { if (parsedMessage.Id is null || !parsedMessage.HasPayload) { // TODO : resources throw new InvalidOperationException("Invalid message structure."); } if (_subscriptionManager.TryGetSubscription( parsedMessage.Id, out ISubscription? subscription)) { IResultParser parser = subscription !.ResultParser; OperationResultBuilder resultBuilder = OperationResultBuilder.New(parser.ResultType); parser.Parse(parsedMessage.Payload, resultBuilder); return(new DataResultMessage(parsedMessage.Id, resultBuilder)); } return(KeepConnectionAliveMessage.Default); }