Apollo: Call a mutation server-side from cron job? [duplicate]

試著忘記壹切 提交于 2020-06-13 00:14:32

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/44172332/apollo-call-a-mutation-server-side-from-cron-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!