Skip to content

Commit

Permalink
Replace EnumDescription with str
Browse files Browse the repository at this point in the history
- Fix typo
  • Loading branch information
thenav56 committed Sep 5, 2023
1 parent d431247 commit 16a4633
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
16 changes: 8 additions & 8 deletions apps/questionnaire/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ class Category2(models.IntegerChoices):
# -- AT_RISK
PEOPLE_AT_RISK = 2201, 'People At risk'
# -- PRIORITIES
PRIOTIY_ISSUES_POP = 2301, 'Priotiy Issues (Pop)'
PRIOTIY_ISSUES_HUM = 2302, 'Priotiy Issues (Hum)'
PRIOTIY_INTERVENTIONS_POP = 2303, 'Priotiy Interventions (Pop)'
PRIOTIY_INTERVENTIONS_HUM = 2304, 'Priotiy Interventions (Hum)'
PRIORITY_ISSUES_POP = 2301, 'Priotiy Issues (Pop)'
PRIORITY_ISSUES_HUM = 2302, 'Priotiy Issues (Hum)'
PRIORITY_INTERVENTIONS_POP = 2303, 'Priotiy Interventions (Pop)'
PRIORITY_INTERVENTIONS_HUM = 2304, 'Priotiy Interventions (Hum)'
# -- CAPACITIES_RESPONSE
GOVERNMENT_LOCAL_AUTHORITIES = 2401, 'Government Local Authorities'
INTERNATIONAL_ORGANISATIONS = 2402, 'International Organisations'
Expand Down Expand Up @@ -289,10 +289,10 @@ class Category4(models.IntegerChoices):
Category2.PEOPLE_AT_RISK,
},
Category1.PRIORITIES: {
Category2.PRIOTIY_ISSUES_POP,
Category2.PRIOTIY_ISSUES_HUM,
Category2.PRIOTIY_INTERVENTIONS_POP,
Category2.PRIOTIY_INTERVENTIONS_HUM,
Category2.PRIORITY_ISSUES_POP,
Category2.PRIORITY_ISSUES_HUM,
Category2.PRIORITY_INTERVENTIONS_POP,
Category2.PRIORITY_INTERVENTIONS_HUM,
},
Category1.CAPACITIES_RESPONSE: {
Category2.GOVERNMENT_LOCAL_AUTHORITIES,
Expand Down
25 changes: 11 additions & 14 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ input DjangoModelFilterInput {
pk: ID!
}

"""Provide label for enum values"""
scalar EnumDescription

input IDFilterLookup {
exact: ID
iExact: ID
Expand Down Expand Up @@ -411,10 +408,10 @@ enum QuestionLeafGroupCategory2TypeEnum {
COPING_MECHANISMS
PHYSICAL_AND_MENTAL_WELLBEING
PEOPLE_AT_RISK
PRIOTIY_ISSUES_POP
PRIOTIY_ISSUES_HUM
PRIOTIY_INTERVENTIONS_POP
PRIOTIY_INTERVENTIONS_HUM
PRIORITY_ISSUES_POP
PRIORITY_ISSUES_HUM
PRIORITY_INTERVENTIONS_POP
PRIORITY_INTERVENTIONS_HUM
GOVERNMENT_LOCAL_AUTHORITIES
INTERNATIONAL_ORGANISATIONS
NATION_AND_LOCAL_ORGANISATIONS
Expand Down Expand Up @@ -484,18 +481,18 @@ type QuestionLeafGroupType {
isHidden: Boolean!
relevant: String!
category1: QuestionLeafGroupCategory1TypeEnum!
category1Display: EnumDescription!
category1Display: String!
category2: QuestionLeafGroupCategory2TypeEnum!
category2Display: EnumDescription!
category2Display: String!
category3: QuestionLeafGroupCategory3TypeEnum
category3Display: EnumDescription
category3Display: String
category4: QuestionLeafGroupCategory4TypeEnum
category4Display: EnumDescription
category4Display: String
createdBy: UserType!
modifiedBy: UserType!
questionnaireId: ID!
type: QuestionLeafGroupTypeEnum!
typeDisplay: EnumDescription!
typeDisplay: String!
}

type QuestionLeafGroupTypeBulkBasicMutationResponseType {
Expand Down Expand Up @@ -553,7 +550,7 @@ type QuestionType {
modifiedBy: UserType!
questionnaireId: ID!
type: QuestionTypeEnum!
typeDisplay: EnumDescription!
typeDisplay: String!
}

type QuestionTypeCountList {
Expand Down Expand Up @@ -705,7 +702,7 @@ type UserMeType {
displayName: String!
email: String!
emailOptOuts: [OptEmailNotificationTypeEnum!]!
emailOptOutsDisplay: [EnumDescription!]!
emailOptOutsDisplay: [String!]!
}

type UserMeTypeMutationResponseType {
Expand Down
16 changes: 4 additions & 12 deletions utils/strawberry/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,7 @@ def _get_serializer_name(_field):
raise Exception(f'{serializer_name=} should have a value')


EnumDescription = strawberry.scalar(
typing.NewType("EnumDescription", str),
description="Provide label for enum values",
serialize=lambda v: v,
parse_value=lambda v: v,
)


def enum_display_field(field: models.query_utils.DeferredAttribute) -> typing.Callable[..., EnumDescription]:
def enum_display_field(field: models.query_utils.DeferredAttribute) -> typing.Callable[..., str]:
_field = field.field

if is_array := isinstance(_field, ArrayField):
Expand All @@ -108,18 +100,18 @@ def _get_value(root) -> None | str | list[str]:
)

@strawberry.field
def array_field_(root) -> list[EnumDescription]:
def array_field_(root) -> list[str]:
return _get_value(root)

if is_array:
return array_field_

@strawberry.field
def field_(root) -> EnumDescription:
def field_(root) -> str:
return _get_value(root)

@strawberry.field
def nullable_field_(root) -> typing.Optional[EnumDescription]:
def nullable_field_(root) -> typing.Optional[str]:
return _get_value(root)

if _field.null:
Expand Down

0 comments on commit 16a4633

Please sign in to comment.