コード例 #1
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));
        }
コード例 #2
0
        public async Task ShouldReceiveDataDefinedBySubscription()
        {
            await this.eventBus.Subscribe(EventBusSubscription.Create <Message>(
                                              "testChannel",
                                              "someClientId",
                                              0,
                                              null,
                                              new { },
                                              e => e.Author == "Bob",
                                              operation));

            OnMessageReceivedEventArgs eventArgs = null;

            this.eventBus.OnMessageReceived += async(OnMessageReceivedEventArgs args) =>
            {
                await Task.Yield();

                eventArgs = args;
            };

            await this.eventBus.Publish(new Message()
            {
                Author = "Bob", Content = "stuff"
            }, "testChannel");


            Assert.AreEqual("testChannel", eventArgs.Channel);
        }
コード例 #3
0
        public async Task DoesntSendDataWhenNoSubscriptionMatchesTheFilter()
        {
            await this.eventBus.Subscribe(EventBusSubscription.Create <Message>(
                                              "testChannel",
                                              "someClientId",
                                              0,
                                              null,
                                              new { },
                                              e => e.Author == "Sam",
                                              operation));

            OnMessageReceivedEventArgs eventArgs = null;

            this.eventBus.OnMessageReceived += async(OnMessageReceivedEventArgs args) =>
            {
                await Task.Yield();

                eventArgs = args;
            };

            await this.eventBus.Publish(new Message()
            {
                Author = "Bob", Content = "stuff"
            }, "testChannel");


            Assert.IsNull(eventArgs);
        }
コード例 #4
0
        public async Task IgnoresMultipleSameSubscriptions()
        {
            await this.eventBus.Subscribe(EventBusSubscription.Create <Message>(
                                              "testChannel",
                                              "someClientId",
                                              0,
                                              null,
                                              new { },
                                              e => e.Author == "Sam",
                                              operation));

            await this.eventBus.Subscribe(EventBusSubscription.Create <Message>(
                                              "testChannel",
                                              "someClientId",
                                              0,
                                              null,
                                              new { },
                                              e => e.Author == "Sam",
                                              operation));

            List <string> clientIds = new List <string>();

            this.eventBus.OnMessageReceived += async(OnMessageReceivedEventArgs args) =>
            {
                await Task.Yield();

                clientIds.Add(args.ClientId);
            };

            await this.eventBus.Publish(new Message()
            {
                Author = "Sam", Content = "stuff"
            }, "testChannel");


            Assert.AreEqual(1, clientIds.Count);
        }