简体   繁体   中英

How do I implement subscriptions in GraphQL HotChocolate?

I am implementing HotChocolate as part of my ASP.NET API. I'm trying to add subscriptions to the chat portion on my app, however, the documentation on the HotChocolate site is not implemented yet. From what I can tell from other sites/frameworks, I can use the C# IObservable<Chat> as the return type for the subscription method.

Can anyone give me an example of a query method or point me towards another resource?

public async Task<IObservable<Message>> GetMessages(Guid chatId) {
  var messages = ..Get chats;

  return messages;
}

However, how does this work from a query standpoint? How do we trigger an event to update this?

Thanks.

Since the original documentation link became obsolete I am posting this new link that refers to our workshop project.

Chapter 7 shows how to do subscriptions in two variants. https://github.com/ChilliCream/graphql-workshop/blob/master/docs/7-subscriptions.md

I hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM