Skip to content

Commit f6acd76

Browse files
committed
Added get_root_type to allow_any
1 parent 67ab53d commit f6acd76

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

graphql_jwt/_compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import graphql
2+
3+
try:
4+
from graphql.execution.execute import GraphQLResolveInfo
5+
except ImportError:
6+
from graphql.execution.base import ResolveInfo as GraphQLResolveInfo # noqa
7+
8+
9+
def get_root_type(info):
10+
if graphql.__version__.startswith("2"):
11+
return getattr(info.schema, f"get_{info.operation.operation}_type")()
12+
return getattr(info.schema, f"{info.operation.operation.value}_type")

graphql_jwt/compat.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

graphql_jwt/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from graphene.utils.thenables import maybe_thenable
1010

1111
from . import exceptions, signals
12-
from .compat import GraphQLResolveInfo
12+
from ._compat import GraphQLResolveInfo
1313
from .refresh_token.shortcuts import create_refresh_token, refresh_token_lazy
1414
from .settings import jwt_settings
1515
from .utils import delete_cookie, set_cookie

graphql_jwt/middleware.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.contrib.auth.middleware import get_user
33
from django.contrib.auth.models import AnonymousUser
44

5-
from .compat import get_operation_name
5+
from ._compat import get_root_type
66
from .path import PathDict
77
from .settings import jwt_settings
88
from .utils import get_http_authorization, get_token_argument
@@ -14,8 +14,8 @@
1414

1515

1616
def allow_any(info, **kwargs):
17-
operation_name = get_operation_name(info.operation.operation).title()
18-
field = info.schema.get_type(operation_name).fields.get(info.field_name)
17+
root_type = get_root_type(info)
18+
field = root_type.fields.get(info.field_name)
1919

2020
if field is None:
2121
return False
@@ -69,7 +69,6 @@ def resolve(self, next, root, info, **kwargs):
6969
if (
7070
_authenticate(context) or token_argument is not None
7171
) and self.authenticate_context(info, **kwargs):
72-
7372
user = authenticate(request=context, **kwargs)
7473

7574
if user is not None:

tests/test_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def info(self, user, **headers):
184184

185185
def info_with_field_mock(self, user, field=None):
186186
info_mock = self.info(user)
187-
info_mock.schema.get_type.return_value = mock.Mock(
187+
info_mock.schema.get_root_type.return_value = mock.Mock(
188188
fields={
189189
"test": field,
190190
}

tests/testcases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import graphene
88
from graphene_django.views import GraphQLView
9+
from graphql.execution.execute import GraphQLResolveInfo
910

10-
from graphql_jwt.compat import GraphQLResolveInfo
1111
from graphql_jwt.decorators import jwt_cookie
1212
from graphql_jwt.settings import jwt_settings
1313
from graphql_jwt.testcases import JSONWebTokenClient, JSONWebTokenTestCase

0 commit comments

Comments
 (0)