Exemple #1
0
        protected async Task HandleStartAsync(OperationMessageContext context)
        {
            var payload   = context.Op.Payload;
            var query     = payload is GraphQLQuery ? payload : context.Op.Payload.ToObject <GraphQLQuery>();
            var options   = context.Connection.Options;
            var exOptions = new ExecutionOptions
            {
                Schema           = _schema,
                OperationName    = query.OperationName,
                Inputs           = query.GetInputs(),
                Query            = query.Query,
                ExposeExceptions = options?.ExposeExceptions ?? false,
                ValidationRules  = options?.ValidationRules,
                UserContext      = options?.BuildUserContext?.Invoke(context)
            };

            var isSubscription = _determinator.IsSubscription(exOptions);

            if (isSubscription)
            {
                var result = await SubscribeAsync(exOptions).ConfigureAwait(false);

                await AddSubscription(context, result).ConfigureAwait(false);

                _log.LogInformation($"Subscription: {context.Op.Id} started");
            }
            else
            {
                var result = await ExecuteAsync(exOptions).ConfigureAwait(false);

                _log.LogInformation($"Subscription: {context.Op.Id} started");
                await context.MessageWriter.WriteMessageAsync(new OperationMessage
                {
                    Type    = MessageTypes.GQL_DATA,
                    Id      = context.Op.Id,
                    Payload = result
                });

                await context.MessageWriter.WriteMessageAsync(new OperationMessage
                {
                    Type = MessageTypes.GQL_COMPLETE,
                    Id   = context.Op.Id
                });

                _log.LogInformation($"Subscription: {context.Op.Id} completed");
            }
        }
Exemple #2
0
 private Task <ExecutionResult> ExecuteAsync(ExecutionOptions options)
 {
     return(_documentExecuter.ExecuteAsync(options));
 }
Exemple #3
0
 private Task <SubscriptionExecutionResult> SubscribeAsync(ExecutionOptions options)
 {
     return(_subscriptionExecuter.SubscribeAsync(options));
 }