Skip to content

Commit cdce3a3

Browse files
author
Rami Chowdhury
committed
Add caveats about mappings to the README
1 parent 48865f1 commit cdce3a3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,32 @@ This project depends on third-party code which is subject to the licenses set fo
7777
### Contributing
7878

7979
Please see the [Contributing Guide](./CONTRIBUTING.md). Note that you must sign the [CLA](./CONTRIBUTOR_LICENSE_AGREEMENT.md).
80+
81+
### Caveats
82+
83+
Note that even though Pydantic is perfectly happy with fields that hold mappings (e.g. dictionaries), because [GraphQL's type system doesn't have them](https://graphql.org/learn/schema/) those fields can't be exported to Graphene types. For instance, this will fail with an error `Don't know how to handle mappings in Graphene`:
84+
85+
``` python
86+
import typing
87+
from graphene_pydantic import PydanticObjectType
88+
89+
class Pet:
90+
pass
91+
92+
class Person:
93+
name: str
94+
pets_by_name: typing.Dict[str, Pet]
95+
96+
class GraphQLPerson(PydanticObjectType):
97+
class Meta:
98+
model = Person
99+
```
100+
101+
However, note that if you use `exclude_fields` or `only_fields` to exclude those values, there won't be a problem:
102+
103+
``` python
104+
class GraphQLPerson(PydanticObjectType):
105+
class Meta:
106+
model = Person
107+
exclude_fields = ("pets_by_name",)
108+
```

0 commit comments

Comments
 (0)