graphene-django-cud
graphene-django-cud copied to clipboard
Nested one-to-one fields
I have nested structure of one-to-one fields.
I have the following models:
class Account(models.Model):
name = models.CharField(max_length=100)
class OrgMember(models.Model):
account = models.OneToOneField(Account, on_delete=models.CASCADE, related_name="member")
class Org(models.Model):
owner = models.OneToOneField(OrgMember, on_delete=models.CASCADE, related_name="org")
and the following mutations:
class AccountType(DjangoObjectType):
class Meta:
model = Account
class OrgMemberType(DjangoObjectType):
class Meta:
model = OrgMember
class OrgType(DjangoObjectType):
class Meta:
model = Org
class CreateAccountMutation(DjangoCreateMutation):
class Meta:
model = Account
class CreateOrgMemberMutation(DjangoCreateMutation):
class Meta:
model = OrgMember
one_to_one_extras = {"account": {"type": "auto"}}
class CreateOrgMutation(DjangoCreateMutation):
class Meta:
model = Org
one_to_one_extras = {"owner": {"type": "auto"}}
class Mutation(graphene.ObjectType):
create_category = CreateOrgMutation.Field()
One level deep an ID is required. This would work
mutation {
createOrg(input: {owner: {account: 1}}){
org{
owner{
account{
name
}
}
}
}
}
Howerever, I would expect that this would work, (which it does not because account requires an ID:
mutation {
createOrg(input: {owner: {account: {name: "Max"}}}){
org{
owner{
account{
name
}
}
}
}
}
I tried "auto" and "Create..Input". That's seems to make no difference. What am I missing here? Or could it be a bug?