Skip to main content

Graphene peewee-async integration

Project description

graphene + peewee-async integration :heart:

Features

  • Querying
    • Fields selection (considered by SELECT statement)

    • Related entities subselection (using foreign key joins)

    • Filters (django-style lookups, like peewee.SelectQuery.filter args)

    • Order (multiple fields, asc/dsc support)

    • Pagination (page, paginate_by support plus unpaginated total count auto-fetching)

  • Mutations (both single object and bulk operating, filtering just like for querying)
    • Create

    • Update

    • Delete

    • Clone

Usage sample

# Define models

class Author(Model):
    name = CharField()
    rating = IntegerField()

class Book(Model):
    name = CharField()
    year = IntegerField()
    author = ForeignKeyField(Author)

# Create nodes

class BookNode(PeeweeObjectType):
    class Meta:
        model = Book
        manager = db_manager

class AuthorNode(PeeweeObjectType):
    class Meta:
        model = Author
        manager = db_manager

# Create connections

class BookConnection(PeeweeConnection):
    class Meta:
        node = BookNode

# Aggregate queries

class Query(ObjectType):
    books = PeeweeConnectionField(BookConnection)

# Create schema

schema = Schema(query=Query, auto_camelcase=False)

# Execute graphql query

result = schema.execute('''
    query {
        books (filters: {author__name__ilike: "%Lovecraft%"}) {
            total
            edges {
                node {
                    id
                    name
                    author {
                        id
                        name
                    }
                }
            }
        }
    }''',
    return_promise=True,
    executor=AsyncioExecutor()
)

# Await result if required (failed queries are usually returning result
#                           synchronously with non-empty `result.errors`
#                           while successful ones requires awaiting
#                           of peewee/DB level queries of course)

if not isinstance(result, ExecutionResult):
    result = await result

# Enjoy the result :)

print(result.data)
#
# ===>
#
# {'books': {
#     'total': 2,
#     'edges': [
#         {'node': {
#             'id': 5,
#             'name': 'Dagon',
#             'author': {
#                 'id': 1,
#                 'name': 'Howard Lovecraft'
#             }
#         }},
#         {'node': {
#             'id': 6,
#             'name': 'At the Mountains of Madness',
#             'author': {
#                 'id': 1,
#                 'name': 'H.P. Lovecraft'
#             }
#         }}
#     ]
# }}

Advanced usage

Be sure to check API tests for advanced query/mutation usages and auto-generating such schema for them.

Install

Install as package:

pip3 install graphene-peewee-async

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphene-peewee-async-3.0.0.tar.gz (16.0 kB view details)

Uploaded Source

File details

Details for the file graphene-peewee-async-3.0.0.tar.gz.

File metadata

  • Download URL: graphene-peewee-async-3.0.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1

File hashes

Hashes for graphene-peewee-async-3.0.0.tar.gz
Algorithm Hash digest
SHA256 65c6dc7e1609cd12540dec5b538894f17288c68f5e8d4c6fe655655a1fd08ea5
MD5 6eea45f5c31d11641d873ac662aa6634
BLAKE2b-256 b32ce390304ca548eb85c8a5421d389d4c2250640455cf14d9660aaf89dbb974

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page