Skip to content

Commit

Permalink
Update optional fields in the examples to align with changes in Pydan…
Browse files Browse the repository at this point in the history
…tic v2. Add a main() function so that this is easier to test
  • Loading branch information
dantheman39 committed Feb 1, 2024
1 parent e15d15d commit 797a4b3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/departments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class SalaryModel(pydantic.BaseModel):


class EmployeeModel(PersonModel):
hired_on: datetime.datetime = None
salary: T.Optional[SalaryModel]
hired_on: T.Optional[datetime.datetime] = None
salary: T.Optional[SalaryModel] = None


class ManagerModel(EmployeeModel):
Expand Down Expand Up @@ -96,13 +96,13 @@ def resolve_list_departments(self, info):
salary=SalaryModel(rating="GS-9", amount=75000.23),
hired_on=datetime.datetime(2019, 1, 1, 15, 26),
),
EmployeeModel(id=uuid.uuid4(), name="Derek"),
EmployeeModel(id=uuid.uuid4(), name="Derek", salary=None),
],
)
]


if __name__ == "__main__":
def main():
schema = graphene.Schema(query=Query)
query = """
query {
Expand All @@ -128,7 +128,10 @@ def resolve_list_departments(self, info):
}
}
"""
result = schema.execute(query)
return schema.execute(query)


if __name__ == "__main__":
result = main()
print(result.errors)
print(json.dumps(result.data, indent=2))

0 comments on commit 797a4b3

Please sign in to comment.