Skip to content

Optional Pydantic field fails in graphql_fields #48

@guy-ecton

Description

@guy-ecton

Describe the bug
Trying to use an Optional Pydantic field with a primitive type (like str)

To Reproduce
Steps to reproduce the behavior:

class Foo(GraphQLQueryBaseModel):
  name: Optional[str] = None

Foo.graphql_fields()

Exception:

AttributeError: type object 'str' has no attribute 'model_fields'
File graphql_query/base_model.py", line 27, in _get_fields
    for f_name, f in model.model_fields.items():
                     ^^^^^^^^^^^^^^^^^^
  • Python: 3.12.8
  • graphql-query: 1.4.0
  • pydantic: 2.10.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions