• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

yfilali/graphql-pynamodb: Graphene PynamoDB Integration

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

yfilali/graphql-pynamodb

开源软件地址(OpenSource Url):

https://github.com/yfilali/graphql-pynamodb

开源编程语言(OpenSource Language):

Python 99.3%

开源软件介绍(OpenSource Introduction):

Graphene-PynamoDB Build Status Coverage Status PyPI version

A PynamoDB integration for Graphene.

Installation

For instaling graphene, just run this command in your shell

pip install graphene-pynamodb

Examples

Here is a simple PynamoDB model:

from uuid import uuid4
from pynamodb.attributes import UnicodeAttribute
from pynamodb.models import Model


class User(Model):
    class Meta:
        table_name = "my_users"
        host = "http://localhost:8000"

    id = UnicodeAttribute(hash_key=True)
    name = UnicodeAttribute(null=False)


if not User.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()

To create a GraphQL schema for it you simply have to write the following:

import graphene
from graphene_pynamodb import PynamoObjectType


class UserNode(PynamoObjectType):
    class Meta:
        model = User
        interfaces = (graphene.Node,)


class Query(graphene.ObjectType):
    users = graphene.List(UserNode)

    def resolve_users(self, args, context, info):
        return list(User.scan())


schema = graphene.Schema(query=Query)

Then you can simply query the schema:

query = '''
    query {
      users {
        name
      }
    }
'''
result = schema.execute(query)

To learn more check out the following examples:

Limitations

graphene-pynamodb includes a basic implementation of relationships using lists. OneToOne and OneToMany relationships are serialized as a List of the ids and unserialized lazyly. The limit for an item's size in DynamoDB is 400KB (see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html) This means the total "row" size including the serialized relationship needs to fit within 400KB so make sure to use this accordingly.

In addition, scan operations on DynamoDB are unsorted by design. This means that there is no reliable way to get a paginated result (Cursor support) on a root PynamoConnectionField.

This means that if you need to paginate items, it is best to have them as a OneToMany relationship inside another Field (usually viewer or node).

Contributing

After cloning this repo, ensure dependencies are installed by running:

python setup.py install

After developing, the full test suite can be evaluated by running:

python setup.py test # Use --pytest-args="-v -s" for verbose mode



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap