title: graphen-django mutation relationships
body: <p>I am attempting to create a mutation with django-graphene that includes a relationship and return the related objects in the response.</p>
  
  <p>Django 1.11.5</p>
  
  <p>graphene-django 1.2.1</p>
  
  <p>Amazon Redshift</p>
  
  <p>Models</p>
  
  <pre><code>import uuid
  
  from django.db import models
  
  from dwtools.sources.base_models import BaseModel
  
  
  class MasterAccount(BaseModel):
      master_id = models.CharField(
          max_length=36, help_text='''The UUID of the record.''',
          unique=True,
          default=uuid.uuid4)
      account_nm = models.CharField(
          max_length=255, null=True, blank=True,
          help_text='''The account's name.''')
  
      class Meta:
          managed = False
          db_table = 'account_dev'
          app_label = 'mappings'
  
  
  class PlatformAccount(BaseModel):
      platform_id = models.BigIntegerField(help_text='''Platform account ID''')
      master = models.ForeignKey(MasterAccount, to_field='master_id')
  
      class Meta:
          managed = False
          db_table = 'platform_dev'
          app_label = 'mappings'
  </code></pre>
  
  <p>GraphQL models</p>
  
  <pre><code>import graphene
  from graphene import ObjectType, String
  
  
  class PlatformAccountGraphQL(ObjectType):
      platform_id = String()
  
  
  class MasterAccountGraphQL(ObjectType):
      master_id = String()
      account_nm = String()
      platform_account = graphene.Field(PlatformAccountGraphQL)
  </code></pre>
  
  <p>Schema</p>
  
  <pre><code>class MasterAccountNode(DjangoObjectType):
      class Meta:
          model = MasterAccount
          interfaces = (relay.Node,)
  
  
  class PlatformAccountNode(DjangoObjectType):
      class Meta:
          model = PlatformAccount
          interfaces = (relay.Node,)
  
  
  class CreateAccount(ClientIDMutation):
      class Input:
          account_nm = String()
  
      ok = Boolean()
      master_account = Field(MasterAccountNode)
      platform_account = Field(PlatformAccountNode)
  
      @classmethod
      def mutate_and_get_payload(cls, args, instance, info):
          ok = True
          master_account = MasterAccount(account_nm=args.get('account_nm'))
  
          master_account.save(force_insert=True)
  
          # Testing ID
          platform_id = 123456
          platform_account = PlatformAccount(master=master_account,
                                             platform_id=platform_id)
          platform_account.save()
  
          return CreateAccount(master_account=master_account,
                               platform_account=platform_account,
                               ok=ok)
  
  
  class Mutations(AbstractType):
      """Mutations for the mappings class."""
  
      create_account = CreateAccount.Field()
  
  
  class Query(AbstractType):
      """The account query class for GraphQL."""
  
      master_account = Field(MasterAccountGraphQL)
      platform_account = Field(PlatformAccountGraphQL)
  </code></pre>
  
  <p>Query</p>
  
  <pre><code>mutation createAccount {
    createAccount(input: {accountNm: "testing account 2"}) {
      masterAccount {
        masterId
        accountNm
        id
        platformaccount {
          edges {
            node {
              platformId
            }
          }
        }
      }
      ok
    }
    __debug {
      sql {
        rawSql
      }
    }
  }
  </code></pre>
  
  <p>Results</p>
  
  <pre><code>   {
    "data": {
      "createAccount": {
        "masterAccount": {
          "masterId": "698afbcb-5c90-43ec-b234-f15e0cd320b0",
          "accountNm": "testing account 2",
          "id": "TWFzdGVyQWNjb3VudE5vZGU6MTU=",
          "platformaccount": {
            "edges": [
              {
                "node": {
                  "platformId": 123456
                }
              },
              {
                "node": {
                  "platformId": 123456
                }
              },
              {
                "node": {
                  "platformId": 123456
                }
              }
            ]
          }
        },
        "ok": true
      },
      "__debug": {
        "sql": [
          {
            "rawSql": "INSERT INTO \"account_dev\" (\"created_dt\", \"created_user\", \"updated_dt\", \"updated_user\", \"master_id\", \"account_nm\") VALUES (%s, %s, %s, %s, %s, %s)"
          },
          {
            "rawSql": "SELECT MAX(id) from \"account_dev\""
          },
          {
            "rawSql": "INSERT INTO \"platform_dev\" (\"created_dt\", \"created_user\", \"updated_dt\", \"updated_user\", \"platform_id\", \"master_id\") VALUES (%s, %s, %s, %s, %s, %s)"
          },
          {
            "rawSql": "SELECT MAX(id) from \"platform_dev\""
          },
          {
            "rawSql": "SELECT COUNT(*) AS \"__count\" FROM \"platform_dev\""
          },
          {
            "rawSql": "SELECT \"platform_dev\".\"id\", \"platform_dev\".\"created_dt\", \"platform_dev\".\"created_user\", \"platform_dev\".\"updated_dt\", \"platform_dev\".\"updated_user\", \"platform_dev\".\"platform_id\", \"platform_dev\".\"master_id\" FROM \"platform_dev\" LIMIT 3"
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>Data appears to be inserted into the two tables correctly. However, what I am looking for in the result is the <code>platformaccount</code> that relates to the <code>masterAccount</code>. I am receiving all <code>platformaccount</code>s in the database and not only the account that is related to the newly created master via the <code>masterId</code>.</p>
  
  <p>How do I get back only related records?</p>