Skip to main content

Usable utility extensions for Ariadne & Django

Project description

ariadne-django-ext

ci status pypi link codecov
supported python versions supported django versions

InstallationContributingLicense

Custom, simple Django User model with email as username

Installation

pip install ariadne-django-ext

Usage

cache

cache decorator will cache a result returned from resolver using Django cache framework. You can it accepts same keyword arguments and passed down to Django cache.

Cache key must be either value or callable. Callable will receive same arguments as resolver then return cache key. Callable may return None to bypass the cache.

It uses typename and key from info.path as cache key prefix.

from ariadne_django_ext import cache

@cache(key='cache_key')
def resolver(parent, info):
    ...
    return 'result'

wrap_result

wrap_result decorator wraps return value of a resolver into dictionary with the key

from ariadne_django_ext import wrap_result

@wrap_result(key='result')
def resolver(parent, info):
    return 'result'

Above example will return following dict

{ "result": "result" }

isAuthenticated & isStaff directive

A resolver will receive an authenticated user as keyword argument.

directive @isAuthenticated on FIELD_DEFINITION

type User {
  id: ID
  username: String
  ipAddress: String @isAuthenticated
}
from ariadne_django_ext import IsAuthenticatedDirective

schema = make_executable_schema(
  type_defs,
  resolvers,
  directives={"isAuthenticated": IsAuthenticatedDirective}
)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT License


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

ariadne-django-ext-1.6.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

ariadne_django_ext-1.6-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

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