在Insomnia中运行突变时,'Request'对象使用graphene python没有属性'get'错误

时间:2018-06-03 15:28:17

标签: graphene-python

我刚开始使用Graphene SQLAlchemy。我已经将石墨烯文档跟踪到T并成功创建了我的GraphQL服务器并且我的查询很好。我继续研究我的突变,但由于缺乏文档和对SQLAlchemy的支持,我设法找到了一个很好的资源(根据link

我已成功整合此gist,当我使用Insomnia进行测试时,出现此错误:

{
    "errors": [
        {
            "message": "'Request' object has no attribute 'get'",
            "locations": [
                {
                    "line": 2,
                    "column": 2
                }
            ]
        }
    ],
    "data": {
        "addCalendarYear": null
    }
}

我的模特:

@dataclass
class UtilsFields():
    priority = Column(Integer, default=0)
    isSynced = Column(Boolean, default=False)
    isDeleted = Column(Boolean, default=False)

@dataclass
class CalendarYear(Base, UtilsFields):
    __tablename__ = 'tblCalendarYears'

    id = Column(Integer, primary_key=True, autoincrement=True)
    year = Column(String(4))

这是我用于突变的子模式:

@dataclass
class UtilsAttributes():

    priority = graphene.Int(default_value=0)
    isSynced = graphene.Boolean(default_value=False)
    isDeleted = graphene.Boolean(default_value=False)


class CalendarYear(SQLAlchemyObjectType):

    class Meta:
        model = CalendarYearModel
        interfaces = (relay.Node, )


class AddCalendarYearInput(SQLAlchemyInputObjectType, UtilsAttributes):

    class Meta:
        model = CalendarYearModel

    year = graphene.String(default_value='')


class AddCalendarYear(SQLAlchemyMutation):

    class Arguments:
        input = graphene.Argument(AddCalendarYearInput)

    class Meta:
        model = CalendarYearModel
        create = True

    Output = CalendarYear

和主要架构:

class Mutate(graphene.ObjectType):
    from my_schemas.calendarSchema import AddCalendarYear

    addCalendarYear = AddCalendarYear.Field()


db_session = scoped_session(
    sessionmaker(
        autocommit=False,
        autoflush=False,
        bind=engine
    )
)

Base = declarative_base()
Base.query = db_session.query_property()

schema = graphene.Schema(
            query=Query,
            mutation=Mutate,
            types=[
                CalendarYear
            ]
        )

schema.execute(context_value={'session': db_session})

这是我在失眠症中的突变:

mutation addYear {
    addCalendarYear(input: {year: "2018"}) {    
        priority
        year
        isSynced
        isDeleted
    }
}

我想知道我是否遗漏了什么。任何帮助是极大的赞赏。 TIA。

0 个答案:

没有答案