Apollo: 从cron job中调用一个突变的服务器端?[英] Apollo: Call a mutation server-side from cron job?

本文是小编为大家收集整理的关于Apollo: 从cron job中调用一个突变的服务器端?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个使用Apollo的流星应用程序,并且我正在使用SyncedCron( https for .com/percolateStudio/Meteor-synced-cron )每2小时安排数据库上的更新操作.

每两个小时,从某些外部API获取X数据,然后存储在数据库的Y集合中.冲洗并重复.

我的问题是:是否应该将此更新操作作为GraphQl突变实现,并从Cron作业中称为服务器端(如果是,您该怎么做?!),或者应该将其作为正常JS函数因为它将仅在服务器上执行吗?

通过将您的视图组件包装在启用GraphQL的HOC中,我可以在线找到所有的突变示例.

也许我只是在误解突变的范围,这里更大的问题是突变是否可以从服务器中调用 ,或者仅是客户端.

.

希望在这里找到有关突变最佳实践的澄清.谢谢!

推荐答案

我认为您将在此处使用Axios(HTTP调用)或流星方法.我认为突变仅适用于浏览器.

本文地址:https://www.itbaoku.cn/post/1938066.html

问题描述

I have a Meteor app that uses Apollo and I am using SyncedCron (https://github.com/percolatestudio/meteor-synced-cron) to schedule an update operation on the database every 2 hours.

Every two hours, fetch X data from some external API and store in Y collection of the database. Rinse and repeat.

My question is this: should this update operation be implemented as a graphQL mutation, and called server-side from within the cron job (if so, how do you do it?!), or should this be implemented as a normal JS function since it will only ever execute on the server?

All the mutation examples I can find online are invoked from the client by wrapping your View component in a graphql-enabled HOC.

Perhaps I am just misunderstanding the scope of mutations, and the larger question here is whether or not mutations CAN be invoked from the server, or if they are client-side only.

Hoping to find some clarification here on mutation best practices. Thanks!

推荐答案

I think you would just use axios (http call) or a meteor method here. I think mutations are just for browser-to-server.