Skip to content

Commit 9d2013f

Browse files
author
Rami Chowdhury
committed
Fix exclude_fields / only_fields
1 parent 492a15f commit 9d2013f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

graphene_pydantic/types.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ def construct_fields(
3131
Currently simply fetches all the attributes from the Pydantic model's __fields__. In
3232
the future we hope to implement field-level overrides that we'll have to merge in.
3333
"""
34-
fields = {}
35-
if only_fields:
36-
fields_to_convert = (
37-
(k, v) for k, v in model.__fields__.items() if k in only_fields
38-
)
39-
elif exclude_fields:
40-
fields_to_convert = (
41-
(k, v) for k, v in model.__fields__.items() if k not in only_fields
42-
)
34+
excluded: typing.Tuple[str, ...] = ()
35+
if exclude_fields:
36+
excluded = exclude_fields
37+
elif only_fields:
38+
excluded = tuple(k for k in model.__fields__ if k not in only_fields)
4339

40+
fields_to_convert = (
41+
(k, v) for k, v in model.__fields__.items() if k not in excluded
42+
)
43+
44+
fields = {}
4445
for name, field in fields_to_convert:
4546
converted = convert_pydantic_field(field, registry)
4647
registry.register_orm_field(obj_type, name, field)

0 commit comments

Comments
 (0)