石墨烯-Pynamodb积分
graphene-pynamodb的Python项目详细描述
安装
要安装石墨烯,只需在shell中运行此命令
pip install graphene-pynamodb
示例
下面是一个简单的pynamodb模型:
fromuuidimportuuid4frompynamodb.attributesimportUnicodeAttributefrompynamodb.modelsimportModelclassUser(Model):classMeta:table_name="my_users"host="http://localhost:8000"id=UnicodeAttribute(hash_key=True)name=UnicodeAttribute(null=False)ifnotUser.exists():User.create_table(read_capacity_units=1,write_capacity_units=1,wait=True)User(id=str(uuid4()),name="John Snow").save()User(id=str(uuid4()),name="Daenerys Targaryen").save()
要为它创建GraphQL模式,只需编写 以下内容:
importgraphenefromgraphene_pynamodbimportPynamoObjectTypeclassUserNode(PynamoObjectType):classMeta:model=Userinterfaces=(graphene.Node,)classQuery(graphene.ObjectType):users=graphene.List(UserNode)defresolve_users(self,args,context,info):returnlist(User.scan())schema=graphene.Schema(query=Query)
然后您可以简单地查询模式:
query=''' query { users { name } } '''result=schema.execute(query)
要了解更多,请查看以下内容 examples:
限制
graphene pynamodb包含一个基本的关系实现,使用 名单onetoone和onetomany关系被序列化为 身份证和未经授权的懒汉。项目大小的限制 DynamoDB是400KB(参见 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html) 这意味着总的“行”大小包括序列化关系 需要在400KB之内,因此请确保相应地使用它
此外,dynamodb上的扫描操作也未按设计排序。这个 意味着没有可靠的方法来获得分页结果(游标 在根PynamoConnectionField上
这意味着,如果您需要对项目进行分页,最好让它们 作为另一个领域内的一对夫妻关系(通常是观察者或 节点)。
贡献
克隆this repo后,确保 依赖项是通过运行来安装的:
python setup.py install
开发完成后,可以通过运行:
python setup.py test# Use --pytest-args="-v -s" for verbose mode