Skip to content

Commit

Permalink
most recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaw9c committed May 4, 2023
1 parent 4e5862f commit c10753d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.11
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down
22 changes: 18 additions & 4 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import OrderedDict
from functools import singledispatch, wraps
from asyncio import get_running_loop
from asgiref.sync import sync_to_async

from django.db import models
from django.utils.encoding import force_str
Expand Down Expand Up @@ -265,17 +266,17 @@ def dynamic_type():
_type = registry.get_type_for_model(model)
if not _type:
return

class CustomField(Field):
def wrap_resolve(self, parent_resolver):
resolver = super().wrap_resolve(parent_resolver)

try:
try:
get_running_loop()
except RuntimeError:
pass
else:
resolver=sync_to_async(resolver)
resolver = sync_to_async(resolver)

return resolver

Expand Down Expand Up @@ -334,7 +335,20 @@ def dynamic_type():
if not _type:
return

return Field(
class CustomField(Field):
def wrap_resolve(self, parent_resolver):
resolver = super().wrap_resolve(parent_resolver)

try:
get_running_loop()
except RuntimeError:
pass
else:
resolver = sync_to_async(resolver)

return resolver

return CustomField(
_type,
description=get_django_field_description(field),
required=not field.null,
Expand Down

0 comments on commit c10753d

Please sign in to comment.