Skip to content

Commit 492a15f

Browse files
author
Rami Chowdhury
committed
Support only_fields and exclude_fields
1 parent 8dc2fdf commit 492a15f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

graphene_pydantic/types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ def construct_fields(
3232
the future we hope to implement field-level overrides that we'll have to merge in.
3333
"""
3434
fields = {}
35-
for name, field in model.__fields__.items():
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+
)
43+
44+
for name, field in fields_to_convert:
3645
converted = convert_pydantic_field(field, registry)
3746
registry.register_orm_field(obj_type, name, field)
3847
fields[name] = converted

0 commit comments

Comments
 (0)