- Notifications
You must be signed in to change notification settings - Fork8
A collection of custom extensions for Graphene Django
License
NotificationsYou must be signed in to change notification settings
flavors/django-graphql-extensions
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A collection of custom extensions forDjango GraphQL
- Python ≥ 3.6
- Django ≥ 2.0
- Graphene-django ≥ 3.0.0b1
Install last stable version from Pypi.
pip install django-graphql-extensions
@login_required@staff_member_required@superuser_required@permission_required@user_passes_test
See thedocumentation to know the full list of decorators.
fromdjango.contrib.authimportget_user_modelimportgraphenefromgraphql_extensions.decoratorsimport (login_required,staff_member_required,)classQuery(graphene.ObjectType):viewer=graphene.Field(UserType)users=graphene.List(UserType)@login_requireddefresolve_viewer(self,info,**kwargs):returninfo.context.user@staff_member_requireddefresolve_users(self,info,**kwargs):returnget_user_model().objects.all()
Returning appropriateerror responses andmasking error messages sent to the client.
Configure yourGraphQLView.
fromdjango.urlsimportinclude,pathfromgraphql_extensions.viewsimportGraphQLViewurlpatterns= [path('',GraphQLView.as_view(),name='index'),]
Exceptions
fromgraphql_extensionsimportexceptions
exceptions.GraphQLErrorexceptions.PermissionDeniedexceptions.ValidationErrorexceptions.NotFound
Payload
{"errors":[{"message":"You do not have permission to perform this action","locations":[{"line":3,"column":13}],"path":["viewer"],"extensions":{"type":"PermissionDenied","code":"permissionDenied","timestamp":1622783872,"data":{},"operation":"QUERY","trace":[" File \"site-packages/graphql/execution/execute.py\", line 617, in resolve_field\n result = resolve_fn(source, info, **args)\n"," File \"graphql_extensions/decorators.py\", line 23, in wrapper\n return func(info.context, *args, **kwargs)\n"," File \"graphql_extensions/decorators.py\", line 35, in wrapper\n raise exc\n"]}}],"data":{"viewer":null}}
This package includes a subclass ofunittest.TestCaseSchemaTestCase and improve support for making GraphQL queries.
fromdjango.contrib.authimportget_user_modelfromgraphql_extensions.testimportSchemaTestCaseclassUsersTests(SchemaTestCase):deftest_create_user(self):query=''' mutation CreateUser($username: String!, $password: String!) { createUser(username: $username, password: $password) { user { id } } }'''response=self.client.execute(query, {'username':'test','password':'dolphins', })self.assertFalse(response.errors)self.assertTrue(response.data['user'])deftest_viewer(self):user=get_user_model().objects.create_user(username='test',password='dolphins', )self.client.authenticate(self.user)query=''' { viewer { username } }'''response=self.client.execute(query)data=response.data['viewer']self.assertEqual(data['username'],user.username)
CustomGraphenetypes.
EmailTimestamp
About
A collection of custom extensions for Graphene Django
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.