예제 #1
0
        private async Task <ExpandoObject> ProcessSubscription(
            GraphQLSubscriptionType type,
            IFieldCollector fieldCollector,
            FieldScope scope)
        {
            var fields           = fieldCollector.CollectFields(type, this.Operation.SelectionSet);
            var field            = fields.Single(); //only single subscription field allowed
            var result           = new ExpandoObject();
            var resultDictionary = (IDictionary <string, object>)result;

            await this.RegisterSubscription(
                field.Value.Single(),
                type,
                this.ast,
                scope);

            resultDictionary.Add("subscriptionId", this.subscriptionId.Value);
            resultDictionary.Add("clientId", this.clientId);

            var returnObject           = new ExpandoObject();
            var returnObjectDictionary = (IDictionary <string, object>)returnObject;

            returnObjectDictionary.Add("data", result);

            if (scope.Errors.Any())
            {
                returnObjectDictionary.Add("errors", scope.Errors);
            }

            return(returnObject);
        }
예제 #2
0
        private async Task RegisterSubscription(
            GraphQLFieldSelection fieldSelection,
            GraphQLSubscriptionType type,
            GraphQLDocument document,
            FieldScope scope)
        {
            var fieldInfo = type.GetFieldInfo(fieldSelection.Name.Value) as GraphQLSubscriptionTypeFieldInfo;

            Expression <Func <object, bool> > filter = null;

            if (fieldInfo.Filter != null)
            {
                filter = entity => (bool)scope.InvokeWithArgumentsSync(
                    fieldSelection.Arguments.ToList(), fieldInfo.Filter, entity);
            }

            await type.EventBus.Subscribe(EventBusSubscription.Create(
                                              fieldInfo.Channel,
                                              this.clientId,
                                              this.subscriptionId.Value,
                                              this.Operation?.Name?.Value ?? "Anonymous",
                                              this.variables,
                                              filter,
                                              this.ast));
        }
예제 #3
0
 public void Subscription(GraphQLSubscriptionType root)
 {
     this.SubscriptionType = root;
     this.SubscriptionType.EventBus.OnMessageReceived += this.InvokeSubscriptionMessageReceived;
 }