public void SubscribeToUpdates()
        {
            var client = new GraphQLHttpClient(httpsLocalhostGraphql, new SystemTextJsonSerializer());

            var query = new GraphQLHttpRequest
            {
                Query = @"subscription { reviewAdded { title productId } }"
            };

            var result = client.CreateSubscriptionStream <ProductReviewSubscriptionResponse>(query);

            //result.Subscribe(response =>
            //{
            //    var review = response.Data;
            //});
        }
        public IObservable <GraphQLResponse <JObject> > WaitingTimeUpdatedStream(string parkId)
        {
            var req = new GraphQLRequest
            {
                Query     = @"
	                    subscription getWaitTime($id: Int) {
                            rides(where:{parkId:{_eq:$id}}) {
                                id
                                waitTime
                            }
                        }",
                Variables = new
                {
                    id = parkId
                }
            };

            return(_graphQLClient.CreateSubscriptionStream <JObject>(req));
        }
Exemplo n.º 3
0
        public void SubscribeToUpdates()
        {
            var request = new GraphQLRequest
            {
                Query = @"subscription {
                              reviewAdded {
                                productId
                                title
                              }
                            }"
            };

            var stream = _client.CreateSubscriptionStream <AddedReviewSubscriptionResult>(
                request: request,
                exceptionHandler: exception => _logger.LogError(exception.Message));

            var subscription = stream.Subscribe(response
                                                => _logger.LogInformation($"A new Review from Product '{response.Data.Review.ProductId}' " +
                                                                          $"was added with Title: {response.Data.Review.Title}"));

            subscription.Dispose();
        }
Exemplo n.º 4
0
        private static IDisposable CreateSubscription(string id, GraphQLHttpClient client)
        {
#pragma warning disable 618
            var stream = client.CreateSubscriptionStream(new GraphQLRequest(@"
					subscription {
						messageAdded{
						content
							from {
								displayName
							}
						}
					}"
                                                                            )
            {
                Variables = new { id }
            });
#pragma warning restore 618

            return(stream.Subscribe(
                       response => Console.WriteLine($"{id}: new message from \"{response.Data.messageAdded.from.displayName.Value}\": {response.Data.messageAdded.content.Value}"),
                       exception => Console.WriteLine($"{id}: message subscription stream failed: {exception}"),
                       () => Console.WriteLine($"{id}: message subscription stream completed")));
        }
Exemplo n.º 5
0
        public async void CanCreateObservableSubscription()
        {
            var callbackMonitor = ChatClient.ConfigureMonitorForOnWebsocketConnected();
            await ChatClient.InitializeWebsocketConnection();

            callbackMonitor.Should().HaveBeenInvokedWithPayload();

            Debug.WriteLine("creating subscription stream");
            var observable = ChatClient.CreateSubscriptionStream <MessageAddedSubscriptionResult>(_subscriptionRequest);

            Debug.WriteLine("subscribing...");
            using var observer = observable.Observe();
            await observer.Should().PushAsync(1);

            observer.RecordedMessages.Last().Errors.Should().BeNullOrEmpty();
            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(InitialMessage.Content);

            const string message1 = "Hello World";
            var          response = await ChatClient.AddMessageAsync(message1);

            response.Errors.Should().BeNullOrEmpty();
            response.Data.AddMessage.Content.Should().Be(message1);
            await observer.Should().PushAsync(2);

            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(message1);

            const string message2 = "lorem ipsum dolor si amet";

            response = await ChatClient.AddMessageAsync(message2);

            response.Data.AddMessage.Content.Should().Be(message2);
            await observer.Should().PushAsync(3);

            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(message2);

            // disposing the client should throw a TaskCanceledException on the subscription
            ChatClient.Dispose();
            await observer.Should().CompleteAsync();
        }