title: How to map mongo subdocuments in GraphQL resolve? I get NULL
body: <p>I'm trying to fetch a set of records in my mongo database using <code>mongoose</code> and send it to the GraphQL resolve function. I can get the documents. But the subdocuments always return null. If there are no sub-documents I get an empty array. For example, my data looks like this:</p>
  
  <pre><code>[
    {
      name: '2222dhjshjshfjfsf',
      address: 'dgdgdsf',
      contactNumber: 'dgdgsdfs',
      logo: 'sfsf',
      billingDetails: 'fdsfsdf',
      assignedEmployee: 'sff',
      keyContactPersons:
      [ { name: 'gdgdg',
          contactNumber: 'dgdfg',
          email: 'gdgdfgdfgdsff@gmail.com',
      } ],
      active: true,
      },
      ...
  ]
  </code></pre>
  
  <p>My resolve function looks like this:</p>
  
  <pre><code>const Company = mongoose.model('Company', new mongoose.Schema(), 'companies');
  
  export default {
    Query: {
      companies: () =&gt;
        new Promise((resolve, reject) =&gt;
          Company.find({})
            .lean()
            .exec((error, doc) =&gt; {
              if (error) {
                reject(error);
              }
  
              resolve(doc);
            }))
    }
  };
  </code></pre>
  
  <p>This is the schema:</p>
  
  <pre><code>const typeDefs = gql`
    type KeyContactPerson {
      name: String!
      contactNumber: String
      email: String
    }
  
    type Company {
      slug: String!
      name: String
      address: String
      contactNumber: String
      logo: String
      billingDetails: String
      assignedEmployee: String
      keyContactsPersons: [KeyContactPerson]
      active: String
    }
  
    type Query {
      company(_id: ID!): Company
      companies: [Company]
    }
  `;
  
  export default makeExecutableSchema({
    typeDefs,
    resolvers
  });
  </code></pre>
  
  <p>When I console log the data <code>doc</code> returned from the find method, it has the correct values. The problem seems to be with the type definition. Here's a sample output I get from my GraphQL query:</p>
  
  <pre><code>{
    "data": {
      "companies": [
        {
          "slug": "abc-4",
          "name": "abc",
          "keyContactsPersons": []
        },
        {
          "slug": "abc-5",
          "name": "abc",
          "keyContactsPersons": null
        },
      ]
    }
  }
  </code></pre>
  
  <p>The first record does not have any <code>keyContactsPersons</code> which is the subdocument. It returns an empty array. The second one has some values. But it returns null. Any idea why this is happening?</p>