Skip to content

dulmandakh/ariadne-django-ext

Repository files navigation

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