Skip to content

Commit a8999f9

Browse files
authored
Merge pull request #3 from upsidetravel/add-caveats-to-readme
Add caveats to readme
2 parents e42b8ae + cdce3a3 commit a8999f9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Person(PydanticObjectType):
3939
exclude_fields = ("id",)
4040

4141
class Query(graphene.ObjectType):
42-
people = graphene.List(User)
42+
people = graphene.List(Person)
4343

4444
def resolve_people(self, info):
4545
return get_people() # function returning `PersonModel`s
@@ -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)