我正在学习如何使用 GraphQL 和 python。我找到了graphene项目及其 SQLAlchemy 和 Flask 扩展。我一直在阅读教程和文档,但无法弄清楚class Meta定义模式时的用途。我目前正在关注本教程。我用谷歌搜索了一下,似乎找不到任何东西。
这是教程中的一些代码。我已经对令我困惑的行发表了评论。
从 graphene_sqlalchemy 导入 SQLAlchemyObjectType
从数据库.model_people 导入 ModelPeople
进口石墨烯
# 创建一个通用类来共同描述查询和突变的人员属性
People属性类:
name = graphene.String(description="此人的姓名。")
height = graphene.String(description="人的身高。")
mass = graphene.String(description="人的质量。")
Hair_color = graphene.String(description="人的头发颜色。")
Skin_color = graphene.String(description="人的肤色。")
eye_color = graphene.String(description="人的眼睛颜色。")
birth_year = graphene.String(description="此人的出生年份。")
性别 = graphene.String(description="该人的性别。")
Planet_id = graphene.ID(description="该人来自的星球的全局 ID。")
url = graphene.String(description="星球大战 API 中人物的 URL。")
People 类(SQLAlchemyObjectType,PeopleAttribute):
“”“人员节点。”“”
# ---------- 这个类是用来做什么的?Flask + 石墨烯 + sqlalchemy 生态系统的哪一部分使用了它?
类元:
模特 = 模特人物
接口 = (graphene.relay.Node,)
I’m trying to created a list of objects using graphql mutation, but have been unsuccessful. I've identified the error, please see code snippets and comment on where the error is propagating.
Note: I'm using Graphene on Flask with Python 2.7
Here’s an example payload:
mutation UserMutation {
createUser(
phones: [
{
“number”: “609-777-7777”,
“label”: “home"
},
{
“number”: “609-777-7778”,
“label”: “mobile"
}
]
)
}
Run Code Online (Sandbox Code Playgroud)
On the schema, I have the following:
class CreateUser(graphene.Mutation):
ok = graphene.Boolean()
...
phones …Run Code Online (Sandbox Code Playgroud)