You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see the following comment in PydanticObjectType.__init_subclass_with_meta__:
# TODO: We don't currently do anything with interfaces, and it would
# be great to handle them as well. Some options include:
# - throwing an error if they're present, because we _can't_ handle them
# - finding a model class with that name and generating an interface
# from it
# - using the nearest common ancestor of multiple types in a Union
Are there any concrete plans to add support for interfaces in the near future? For my particular use case, I'd be happy with manually defining interfaces rather than deducing them. For example, I'd like to be able to do this:
# this model will be used to define an interface
class HasIdentityModel(pydantic.BaseModel):
name: str
id: str
class IdentityListModel(pydantic.BaseModel):
things_with_ids: list[HasIdentityModel]
class PersonModel(HasIdentityModel):
age: int
class BusinessModel(HasIdentityModel):
owner: PersonModel
# would have to define PydanticInterfaceType similarly to PydanticObjectType
class HasIdentity(PydanticInterfaceType):
class Meta:
model = HasIdentityModel
class IdentityList(PydanticObjectType):
class Meta:
model = IdentityListModel
class Person(PydanticObjectType):
class Meta:
model = PersonModel
interfaces = (HasIdentity,) # or (HasIdentityModel, ) if that's more appropriate
class Business(PydanticObjectType):
class Meta:
model = BusinessModel
interfaces = (HasIdentity,) # as above
and then query the thingsWithIds field as
thingsWithId: {
name
id
...on Person {
age
}
...on Business {
owner {
name
}
}
}
without having to put the name and id fields on the Person or Business fragments.
The text was updated successfully, but these errors were encountered:
I see the following comment in
PydanticObjectType.__init_subclass_with_meta__
:Are there any concrete plans to add support for interfaces in the near future? For my particular use case, I'd be happy with manually defining interfaces rather than deducing them. For example, I'd like to be able to do this:
and then query the
thingsWithIds
field aswithout having to put the
name
andid
fields on thePerson
orBusiness
fragments.The text was updated successfully, but these errors were encountered: