Skip to content

Commit

Permalink
Merge pull request #320 from flavors/fix/allow-any
Browse files Browse the repository at this point in the history
Fix allow_any function, support any root type name
  • Loading branch information
mongkok committed Aug 4, 2023
2 parents 67ab53d + f8ef841 commit a8941a1
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 1,370 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2

- name: Install Poetry
uses: abatilo/[email protected]
- uses: actions/checkout@v3
- uses: actions/setup-python@v4

- name: Install dependencies
run: poetry install
run: pip install .[doc]

- name: Build docs
run: poetry run sphinx-build -b html docs docs/_build
run: sphinx-build -b html docs docs/_build

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ name: Publish

on:
release:
types: created
types: [created]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4

- name: Install Poetry
uses: abatilo/[email protected]
- name: Install dependencies
run: pip install build

- name: Build
run: poetry build
run: python -m build

- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
30 changes: 14 additions & 16 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ on: [push, pull_request]

jobs:
build:
name: build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }})
runs-on: ubuntu-18.04
name: Build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
django-version: ['2.0', '2.1', '2.2', '3.0', '3.1', '3.2']
python-version: ['3.8', '3.9', '3.10']
django-version: ['3.0', '3.1', '3.2', '4.0', '4.1', '4.2']

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: py-${{ matrix.python-version }}-django-${{ matrix.django-version }}-${{ hashFiles('**/poetry.lock') }}
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ matrix.python-version }}-django-${{ matrix.django-version }}-${{ hashFiles('pyproject.toml') }}

- name: Install Poetry
uses: abatilo/[email protected]
- name: Install Django
run: pip install django==${{ matrix.django-version }}

- name: Install dependencies
run: |
poetry add django==${{ matrix.django-version }}
poetry install
run: pip install -e .[test]

- name: Tests
run: poetry run scripts/test.sh
run: scripts/test.sh

- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ coverage.xml
dist/
docs/_build/
htmlcov/
venv/
12 changes: 12 additions & 0 deletions graphql_jwt/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import graphql

try:
from graphql.execution.execute import GraphQLResolveInfo
except ImportError:
from graphql.execution.base import ResolveInfo as GraphQLResolveInfo # noqa


def get_root_type(info):
if graphql.__version__.startswith("2"):
return getattr(info.schema, f"get_{info.operation.operation}_type")()
return getattr(info.schema, f"{info.operation.operation.value}_type")
10 changes: 0 additions & 10 deletions graphql_jwt/compat.py

This file was deleted.

2 changes: 1 addition & 1 deletion graphql_jwt/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from graphene.utils.thenables import maybe_thenable

from . import exceptions, signals
from .compat import GraphQLResolveInfo
from ._compat import GraphQLResolveInfo
from .refresh_token.shortcuts import create_refresh_token, refresh_token_lazy
from .settings import jwt_settings
from .utils import delete_cookie, set_cookie
Expand Down
7 changes: 3 additions & 4 deletions graphql_jwt/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.middleware import get_user
from django.contrib.auth.models import AnonymousUser

from .compat import get_operation_name
from ._compat import get_root_type
from .path import PathDict
from .settings import jwt_settings
from .utils import get_http_authorization, get_token_argument
Expand All @@ -14,8 +14,8 @@


def allow_any(info, **kwargs):
operation_name = get_operation_name(info.operation.operation).title()
field = info.schema.get_type(operation_name).fields.get(info.field_name)
root_type = get_root_type(info)
field = root_type.fields.get(info.field_name)

if field is None:
return False
Expand Down Expand Up @@ -69,7 +69,6 @@ def resolve(self, next, root, info, **kwargs):
if (
_authenticate(context) or token_argument is not None
) and self.authenticate_context(info, **kwargs):

user = authenticate(request=context, **kwargs)

if user is not None:
Expand Down
1 change: 0 additions & 1 deletion graphql_jwt/refresh_token/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Loading

0 comments on commit a8941a1

Please sign in to comment.