Skip to content

Commit

Permalink
Merge pull request #2133 from winged/feat_update_graphene
Browse files Browse the repository at this point in the history
Feat update graphene
  • Loading branch information
winged authored Jan 30, 2024
2 parents 1578fbf + d04282b commit 8705f20
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
32 changes: 32 additions & 0 deletions caluma/caluma_core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,38 @@ def _should_include_filter(filt):
return filter_coll()


def InterfaceMetaFactory():
"""
Metaclass factory for interface types.
Build a meta class suitable for the schema type classes that represent
"interface" types (those that have concrete subclasses, but could be mixed
in a connection type, such as Question, Answer, and Task).
Usage:
>>> class Foo(Node, graphene.Interface):
>>> ...
>>> Meta = InterfaceMetaFactory()
"""

class _meta(graphene.types.interface.InterfaceOptions):
@classmethod
# This is kinda useless but required as graphene tries to freeze()
# it's meta class objects
def freeze(cls):
cls._frozen = True

# This is what we're actually "fixing": On non-Interface types,
# this somehow works (or isn't needed), but here, if _meta.registry
# is not set, the whole schema construction fails
registry = get_global_registry()

# We need a new type (= class) each time it's called, because reuse
# triggers some weird errors
return type("Meta", (), {"_meta": _meta})


def CollectionFilterSetFactory(filterset_class, orderset_class=None):
"""
Build single-filter filterset classes.
Expand Down
5 changes: 5 additions & 0 deletions caluma/caluma_form/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CollectionFilterSetFactory,
DjangoFilterConnectionField,
DjangoFilterInterfaceConnectionField,
InterfaceMetaFactory,
)
from ..caluma_core.mutation import Mutation, UserDefinedPrimaryKeyMixin
from ..caluma_core.relay import extract_global_id
Expand Down Expand Up @@ -159,6 +160,8 @@ def get_queryset(cls, queryset, info):
def resolve_type(cls, instance, info):
return resolve_question(instance)

Meta = InterfaceMetaFactory()


class Option(FormDjangoObjectType):
meta = generic.GenericScalar()
Expand Down Expand Up @@ -810,6 +813,8 @@ class Answer(Node, graphene.Interface):
def resolve_type(cls, instance, info):
return resolve_answer(instance)

Meta = InterfaceMetaFactory()


class AnswerQuerysetMixin(object):
"""Mixin to combine all different answer types into one queryset."""
Expand Down
5 changes: 4 additions & 1 deletion caluma/caluma_form/tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ def test_complex_document_query_performance(
}
"""

with django_assert_num_queries(7):
with django_assert_num_queries(10):
# TODO: This used to be 7 queries with graphene 3.0.0b7.
# it seems that `Form` is queried that wasn't before, and
# some question options as well.
result = schema_executor(query, variable_values={"id": str(document.pk)})
assert not result.errors

Expand Down
3 changes: 3 additions & 0 deletions caluma/caluma_workflow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CollectionFilterSetFactory,
DjangoFilterConnectionField,
DjangoFilterInterfaceConnectionField,
InterfaceMetaFactory,
)
from ..caluma_core.mutation import Mutation, UserDefinedPrimaryKeyMixin
from ..caluma_core.types import (
Expand Down Expand Up @@ -97,6 +98,8 @@ def resolve_type(cls, instance, info):

return TASK_TYPE[instance.type]

Meta = InterfaceMetaFactory()


class TaskConnection(CountableConnectionBase):
class Meta:
Expand Down
15 changes: 15 additions & 0 deletions caluma/tests/__snapshots__/test_schema.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,21 @@
type DjangoDebug {
"""Executed SQL queries for this API query."""
sql: [DjangoDebugSQL]

"""Raise exceptions for this API query."""
exceptions: [DjangoDebugException]
}

"""Represents a single exception raised."""
type DjangoDebugException {
"""The class of the exception"""
excType: String!

"""The message of the exception"""
message: String!

"""The stack trace"""
stack: String!
}

"""Represents a single database query made to a Django managed DB."""
Expand Down
17 changes: 9 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ django-postgres-extra = "^2.0.8"
django-watchman = "^1.3.0"
djangorestframework = "^3.14.0"
django-simple-history = "^3.4.0"
graphene-django = "3.0.0b7"
graphene-django = "3.2.0"
graphql-relay = "^3.1.5"
idna = "^3.6"
minio = "^7.2.3"
Expand Down Expand Up @@ -104,6 +104,7 @@ filterwarnings = [
# warning in python 3.12 about deprecation coming in 3.14. issue is with graphene
"ignore:.*typing.ByteString.*deprecated and slated for removal in Python 3.14",
"ignore:The 'arrayconnection' module is deprecated:DeprecationWarning", # deprecation in graphene
"ignore:'cgi' is deprecated:DeprecationWarning",
"ignore:distutils Version classes are deprecated:DeprecationWarning", # deprecation in pytest-freezegun
"ignore:'django_extensions' defines default_app_config:PendingDeprecationWarning", # deprecation in django_extensions
"ignore::requests.packages.urllib3.exceptions.InsecureRequestWarning", # MinIO tests do "insecure" requests - that's ok
Expand Down

0 comments on commit 8705f20

Please sign in to comment.