gpt4 book ai didi

In a GraphQL server, what is the best practice for triggering a subscription event from data received that needs to be parsed first?(在GraphQL服务器中,从需要首先解析的数据触发订阅事件的最佳实践是什么?)

转载 作者:bug小助手 更新时间:2023-10-24 20:50:24 24 4
gpt4 key购买 nike



Example:

示例:


I receive data in a string that needs to be parsed first, for example an IoT message.

我接收需要首先解析的字符串形式的数据,例如物联网消息。


I can create a mutation for that no problem, I'm just storing a string in a DB, however, based on what was in the string, I then want to save the data of the different types parsed, so I will have a switch statement in the resolver.

我可以为此创建一个变异,没有问题,我只是将一个字符串存储在数据库中,但是,根据字符串中的内容,我想保存解析的不同类型的数据,所以我将在解析器中有一个Switch语句。


If I save the new types directly to the DB, they will not trigger a subscription.

如果我将新类型直接保存到数据库,它们将不会触发订阅。


If I save via calling the type's mutation (so calling a mutation within a mutation of the same schema), then it will trigger a subscription in my application, which is the desired effect.

如果我通过调用类型的突变来保存(因此调用相同模式的突变中的突变),那么它将在我的应用程序中触发订阅,这是所需的效果。


Is this bad practice? Is there a better, recommended way of doing this?

这是不是很糟糕的做法?有没有更好的、推荐的方法呢?


更多回答

That depends entirely on the server framework that you are using. I'm sure the event to refresh the subscription can also be fired manually, without using a mutation - in the mutation it just is included by default.

这完全取决于您使用的服务器框架。我确信,刷新订阅的事件也可以手动触发,而不使用突变--在突变中,它只是默认包括在内。

@Bergi doh yeah I should've probably thought of that! I'll check, thank you!

@Bergi doh是的,我应该想到这一点的!我查一下,谢谢!

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com