private static void WriteExtensions(OperationRequest request, Utf8JsonWriter writer)
 {
     if (request.GetExtensionsOrNull() is { Count : > 0 } extensions)
     {
         writer.WritePropertyName("extensions");
         WriteDictionary(extensions, writer);
     }
 }
Beispiel #2
0
        /// <inheritdoc />
        public async ValueTask <IExecutionResult> ExecuteAsync(
            OperationRequest request,
            CancellationToken cancellationToken = default)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (Executor is null)
            {
                throw ThrowHelper.InMemoryClient_NoExecutorConfigured(_name);
            }

            var requestBuilder = new QueryRequestBuilder();

            if (request.Document.Body.Length > 0)
            {
                requestBuilder.SetQuery(Utf8GraphQLParser.Parse(request.Document.Body));
            }
            else
            {
                requestBuilder.SetQueryId(request.Id);
            }

            requestBuilder.SetOperation(request.Name);
            requestBuilder.SetVariableValues(CreateVariables(request.Variables));
            requestBuilder.SetExtensions(request.GetExtensionsOrNull());
            requestBuilder.SetProperties(request.GetContextDataOrNull());

            IServiceProvider applicationService = Executor.Services.GetApplicationServices();

            foreach (var interceptor in RequestInterceptors)
            {
                await interceptor
                .OnCreateAsync(applicationService, request, requestBuilder, cancellationToken)
                .ConfigureAwait(false);
            }

            return(await Executor
                   .ExecuteAsync(requestBuilder.Create(), cancellationToken)
                   .ConfigureAwait(false));
        }