简体   繁体   English

如何在 GraphQL HotChocolate 中实现订阅?

[英]How do I implement subscriptions in GraphQL HotChocolate?

I am implementing HotChocolate as part of my ASP.NET API.我正在实现HotChocolate作为我的 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.我正在尝试向我的应用程序的聊天部分添加订阅,但是,HotChocolate 站点上的文档尚未实现。 From what I can tell from other sites/frameworks, I can use the C# IObservable<Chat> as the return type for the subscription method.从我从其他站点/框架中得知的情况来看,我可以使用 C# IObservable<Chat>作为订阅方法的返回类型。

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.第 7 章展示了如何在两种变体中进行订阅。 https://github.com/ChilliCream/graphql-workshop/blob/master/docs/7-subscriptions.md https://github.com/ChilliCream/graphql-workshop/blob/master/docs/7-subscriptions.md

I hope that helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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