Skip to content

Commit 797a4b3

Browse files
committed
Update optional fields in the examples to align with changes in Pydantic v2. Add a main() function so that this is easier to test
1 parent e15d15d commit 797a4b3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

examples/departments.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class SalaryModel(pydantic.BaseModel):
2121

2222

2323
class EmployeeModel(PersonModel):
24-
hired_on: datetime.datetime = None
25-
salary: T.Optional[SalaryModel]
24+
hired_on: T.Optional[datetime.datetime] = None
25+
salary: T.Optional[SalaryModel] = None
2626

2727

2828
class ManagerModel(EmployeeModel):
@@ -96,13 +96,13 @@ def resolve_list_departments(self, info):
9696
salary=SalaryModel(rating="GS-9", amount=75000.23),
9797
hired_on=datetime.datetime(2019, 1, 1, 15, 26),
9898
),
99-
EmployeeModel(id=uuid.uuid4(), name="Derek"),
99+
EmployeeModel(id=uuid.uuid4(), name="Derek", salary=None),
100100
],
101101
)
102102
]
103103

104104

105-
if __name__ == "__main__":
105+
def main():
106106
schema = graphene.Schema(query=Query)
107107
query = """
108108
query {
@@ -128,7 +128,10 @@ def resolve_list_departments(self, info):
128128
}
129129
}
130130
"""
131-
result = schema.execute(query)
131+
return schema.execute(query)
132+
132133

134+
if __name__ == "__main__":
135+
result = main()
133136
print(result.errors)
134137
print(json.dumps(result.data, indent=2))

0 commit comments

Comments
 (0)