1

我编写了一个在前端触发的突变,并且我为 django 构建了一个自定义电子邮件系统,它使用 gql 来查询所需的确切上下文。在突变中,有可能触发电子邮件。但是,当这种情况发生时,突变和查询都会停止。到目前为止,我的解决方案是将电子邮件触发器推送到一项任务中,这似乎可行,但并不理想。关于如何在不需要任务的情况下让它工作的任何想法?

# Super simplified example

class MyEmail(CustomEmailClass):
    def __init__(self, thing):
        self.thing = thing

    @cached_property
    def context(self):
        return schema.execute_query(query, variable_values={
            'thingId': self.thing.id,
        )

    def send(self):
        # get templates and do other things
        # ...
        EmailMultiAlternatives(
            body=plaintext_template.render(self.context),
            **kwargs).send()

class MyMutation(relay.ClientIdMutation):
    class Input:
        id = ID()

    @classmethod
    def mutate_and_get_payload(cls, input, context, info):
        # do things here
        # ...
        MyEmail(thing=instance).send()
        return MyMutation(instance=instance)
4

0 回答 0