graphql-python / graphql-python/graphene-sqlalchemy

MVC: support business logic layer

未关闭
#411 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
985
派生
223
PR 合并指标
30 天内没有已合并 PR

描述

We have Model and View aka Node, but we lack a way to write code between them.

```Python
class PetBusinessLogic:
def __init__(self, pet):
self.pet = pet

@property
def name1(self):
return self.pet.name + "!"

@property
def name2(self):
return self.pet.name + "!"

class Pet(SQLAlchemyObjectType):
class Meta:
model = PetModel
name = "Pet"
interfaces = (relay.Node,)
batching = True

def resolve_name1(node, info):
# write here application logic code for a large project is not good idea.
# so we need some controller aka PetBusinessLogic
return PetBusinessLogic(node).name1 # DRY and I would like to initialize it once

def resolve_name2(node, info):
return PetBusinessLogic(node).name2 # DRY and I would like to initialize it once
```

Any suggestions for this design problem?
*(put this PetBusinessLogic into model is also bad idea)

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。