Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested one-to-one fields #98

Open
HendrikLevering opened this issue Jul 21, 2022 · 0 comments
Open

Nested one-to-one fields #98

HendrikLevering opened this issue Jul 21, 2022 · 0 comments

Comments

@HendrikLevering
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant