Skip to content

Commit

Permalink
Graphene django v3 (projectcaluma#1649)
Browse files Browse the repository at this point in the history
* chore: coverage back to 100%

* chore: fix conflict in setup.py

* fix(schema): use explicit types for case status and workitem status

Graphene would otherwise use an automatic naming scheme that breaks our clients
  • Loading branch information
David Vogt authored and fugal-dy committed Feb 16, 2022
1 parent b5eb3f8 commit 9e6b6cd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
25 changes: 23 additions & 2 deletions caluma/caluma_workflow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ class GroupJexl(graphene.String):
)


CaseStatus = graphene.Enum(
"CaseStatus",
[(key.upper(), key) for key, _ in models.Case.STATUS_CHOICE_TUPLE],
)

WorkItemStatus = graphene.Enum(
"WorkItemStatus",
[(key.upper(), key) for key, _ in models.WorkItem.STATUS_CHOICE_TUPLE],
)


serializer_converter.get_graphene_type_from_serializer_field.register(
serializers.CaseStatusField, lambda field: CaseStatus
)
serializer_converter.get_graphene_type_from_serializer_field.register(
serializers.WorkItemStatusField, lambda field: WorkItemStatus
)


class Task(Node, graphene.Interface):
id = graphene.ID(required=True)
created_at = graphene.DateTime(required=True)
Expand Down Expand Up @@ -104,7 +123,7 @@ class Meta:
class CompleteWorkflowFormTask(TaskQuerysetMixin, DjangoObjectType):
class Meta:
model = models.Task
exclude = ("task_flows", "work_items", "form")
exclude = ("task_flows", "work_items", "form", "type")
use_connection = False
interfaces = (Task, relay.Node)

Expand All @@ -114,7 +133,7 @@ class CompleteTaskFormTask(TaskQuerysetMixin, DjangoObjectType):

class Meta:
model = models.Task
exclude = ("task_flows", "work_items")
exclude = ("task_flows", "work_items", "type")
use_connection = False
interfaces = (Task, relay.Node)

Expand Down Expand Up @@ -168,6 +187,7 @@ class Meta:
class WorkItem(DjangoObjectType):
task = graphene.Field(Task, required=True)
meta = generic.GenericScalar()
status = WorkItemStatus(required=True)
assigned_users = graphene.List(graphene.String, required=True)
controlling_groups = graphene.List(graphene.String, required=True)
addressed_groups = graphene.List(graphene.String, required=True)
Expand All @@ -192,6 +212,7 @@ class Case(DjangoObjectType):
),
)
meta = generic.GenericScalar()
status = CaseStatus(required=True)

def resolve_family_work_items(self, info, **args):
return models.WorkItem.objects.filter(case__family=self.family)
Expand Down
10 changes: 10 additions & 0 deletions caluma/caluma_workflow/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def __init__(self, **kwargs):
super().__init__(GroupJexl(), **kwargs)


class CaseStatusField(serializers.CalumaChoiceField):
def __init__(self, **kwargs):
super().__init__([s for s, _ in models.Case.STATUS_CHOICE_TUPLE], **kwargs)


class WorkItemStatusField(serializers.CalumaChoiceField):
def __init__(self, **kwargs):
super().__init__([s for s, _ in models.WorkItem.STATUS_CHOICE_TUPLE], **kwargs)


class SaveWorkflowSerializer(serializers.ModelSerializer):
class Meta:
model = models.Workflow
Expand Down
69 changes: 19 additions & 50 deletions caluma/tests/__snapshots__/test_schema.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -278,51 +278,6 @@
id: ID!
}

"""An enumeration."""
enum CalumaWorkflowCaseStatusChoices {
"""Case is running and work items need to be completed."""
RUNNING

"""Case is done."""
COMPLETED

"""Case is canceled."""
CANCELED

"""Case is suspended."""
SUSPENDED
}

"""An enumeration."""
enum CalumaWorkflowTaskTypeChoices {
"""Task which can simply be marked as completed."""
SIMPLE

"""Task to complete a defined workflow form."""
COMPLETE_WORKFLOW_FORM

"""Task to complete a defined task form."""
COMPLETE_TASK_FORM
}

"""An enumeration."""
enum CalumaWorkflowWorkItemStatusChoices {
"""Work item is ready to be processed."""
READY

"""Work item is done."""
COMPLETED

"""Work item is canceled."""
CANCELED

"""Work item is skipped."""
SKIPPED

"""Work item is suspended."""
SUSPENDED
}

input CancelCaseInput {
id: ID!

Expand Down Expand Up @@ -365,7 +320,7 @@
closedByUser: String
closedByGroup: String
workflow: Workflow!
status: CalumaWorkflowCaseStatusChoices!
status: CaseStatus!
meta: GenericScalar
document: Document
workItems(
Expand Down Expand Up @@ -568,6 +523,14 @@
META_FOOBAR_DESC
}

"""An enumeration."""
enum CaseStatus {
RUNNING
COMPLETED
CANCELED
SUSPENDED
}

"""An enumeration."""
enum CaseStatusArgument {
"""Case is running and work items need to be completed."""
Expand Down Expand Up @@ -676,7 +639,6 @@
slug: String!
name: String!
description: String
type: CalumaWorkflowTaskTypeChoices!
meta: GenericScalar!
addressGroups: GroupJexl
controlGroups: GroupJexl
Expand Down Expand Up @@ -714,7 +676,6 @@
slug: String!
name: String!
description: String
type: CalumaWorkflowTaskTypeChoices!
meta: GenericScalar!
addressGroups: GroupJexl
controlGroups: GroupJexl
Expand Down Expand Up @@ -3634,7 +3595,6 @@
slug: String!
name: String!
description: String
type: CalumaWorkflowTaskTypeChoices!
meta: GenericScalar!
addressGroups: GroupJexl
controlGroups: GroupJexl
Expand Down Expand Up @@ -4292,7 +4252,7 @@
closedByGroup: String
deadline: DateTime
task: Task!
status: CalumaWorkflowWorkItemStatusChoices!
status: WorkItemStatus!
meta: GenericScalar

"""
Expand Down Expand Up @@ -4439,6 +4399,15 @@
META_FOOBAR_DESC
}

"""An enumeration."""
enum WorkItemStatus {
READY
COMPLETED
CANCELED
SKIPPED
SUSPENDED
}

"""An enumeration."""
enum WorkItemStatusArgument {
"""Work item is ready to be processed."""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ filterwarnings =
source=.

[coverage:report]
fail_under=80
fail_under=100
exclude_lines =
pragma: no cover
pragma: todo cover
Expand Down

0 comments on commit 9e6b6cd

Please sign in to comment.