Skip to main content

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

Release files for graphene-pynamodb 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphene-pynamodb 2.3.0
File Size Uploaded
graphene-pynamodb-2.3.0.tar.gz 15.1 kB Details

Release files / graphene-pynamodb-2.3.0.tar.gz

Download URL graphene-pynamodb-2.3.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0dc5758804ba451f13457bb27ed6655fbb42da1230fa346f358c8d6c2fc5abba
BLAKE2b-256 checksum
How to use checksums
214314cf1d99047993bd474a9281435be7d18b54c004afcade9abd62a4522a66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

2.3.0 This release

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page