SQLAlchemy模型中的Non-SQLAlchemy属性

时间:2019-06-21 19:20:00

标签: graphql graphene-python graphene-sqlalchemy

让我们定义这个模型:

class AccountModel(Base):
    __tablename__ = 'Accounts'
    account_id = Column(Integer, primary_key=True)
    name = Column(String)
    objects = relationship(ObjectModel, back_populates="account")

我还有一个非SQLAlchemy,Graphene本机ObjectType,它通过REST调用填充,我想将其添加到AccountModel:

class AccountMeta(ObjectType):
    status = String()
    account_type = String()
    lineage = String()

当我尝试像这样直接向模型添加属性时:

class AccountModel(Base):
    __tablename__ = 'Accounts'
    account_id = Column(Integer, primary_key=True)
    name = Column(String)
    objects = relationship(ObjectModel, back_populates="account")
    metadata = AccountMeta()

我收到以下错误:AttributeError: 'AccountMeta' object has no attribute 'schema'

这仍然感觉不对,因为我需要将account_id属性传递给解析器,而且我不确定相关SQLAlchemyObjectType中的解析器是否引用了该上下文中存在的属性:

class AccountDb(SQLAlchemyObjectType):
    class Meta:
        model = AccountModel
        interfaces = (relay.Node,)

    def resolve_metadata(self, info):
        return get_account_meta(self.account_id)

如果有任何信息,我似乎找不到太多。这些混合类型的特性可能吗?如果没有,有办法解决吗?

0 个答案:

没有答案