title: graphql sequlize dataloader issue, Cannot return null for non-nullable field
body: <p>schema for ip address: </p>
  
  <pre><code>import { gql } from 'apollo-server-express';
  
  module.exports = gql`
      extend type Query {
          # allTxn: [SubscrTxn]
          cblockIp(ip_key: Int!): CblockIp
      }
  
      type CblockIp {
          ip_key: Int!
          ip_address: String
          cblock_key: Int!
      }
  `;
  </code></pre>
  
  <p>I've created a data-loader but I get "errors": </p>
  
  <pre><code>[
      {
        "message": "Cannot return null for non-nullable field ConfigProxy.ip_key.",
  </code></pre>
  
  <p>if I require the field <code>ip_key: CblockIp!</code> 
  And if I remove the "!" from <code>ip_key: CblockIp</code> the ip_key is null :) </p>
  
  <pre><code>{
    "data": {
      "config": {
        "config_name": "FF0RFQH0",
        "configProxy": [
          {
            "proxy_key": 4351701,
            "ip_key": null
          },
          {
            "proxy_key": 4351702,
            "ip_key": null
          },
          {
            "proxy_key": 4351703,
            "ip_key": null
          },
          {
            "proxy_key": 4351700,
            "ip_key": null
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>My files look like this: </p>
  
  <p><code>app.js</code> part of it: </p>
  
  <pre><code>import DataLoader from 'dataloader';
  import { proxyBatcher } from './batchFunctions';
  
  const server = new ApolloServer({
      typeDefs,
      resolvers,
      context: ({ req }) =&gt; ({
          models,
          secret: process.env.JWT_SECRET,
          member: getLoggedInUser(req),
          me: getLoggedInUser(req),
          proxyLoader: new DataLoader((keys) =&gt; proxyBatcher(keys, models))
      })
  });
  </code></pre>
  
  <p><code>batchFunctions.js</code>: </p>
  
  <pre><code>import _ from 'lodash';
  import { Op } from 'sequelize';
  
  export const proxyBatcher = async (keys, { CblockIp }) =&gt; {
      const proxies = await CblockIp.findAll({
          raw: true,
          where: {
              ip_key: {
                  [Op.in]: keys
              }
          }
      });
  
      const gp = _.groupBy(proxies, 'ip_key');
      console.log(proxies);
      console.log(gp);
      console.log(keys.map((k) =&gt; gp[k] || []));
  
      return keys.map((k) =&gt; gp[k] || []);
  };
  
  export const dummy = 5;
  </code></pre>
  
  <p>configProxy.js (resolver) : </p>
  
  <pre><code>import { requiresAuth } from '../permissions';
  
  const resolvers = {
      Query: {
          // configs: (parent, args, { models }) =&gt; {
          //  return models.Config.findAll();
          // },
          configProxy: requiresAuth.createResolver(
              (parent, { proxy_key }, { models }) =&gt; {
                  return models.ConfigProxy.findOne({
                      where: {
                          proxy_key
                      }
                  });
              }
          )
      },
      ConfigProxy: {
          config_key: (parent, args, { models }) =&gt; {
              return models.Config.findByPk(parent.config_key);
          },
          ip_key: (parent, args, { proxyLoader }) =&gt; {
              proxyLoader.load(parent.ip_key);
              //return models.CblockIp.findByPk(parent.ip_key)
          }
      }
  };
  </code></pre>
  
  <p>if in my resolver i replace { proxyLoader } with { models } and this line </p>
  
  <pre><code>proxyLoader.load(parent.ip_key);
  </code></pre>
  
  <p>with </p>
  
  <pre><code>return models.CblockIp.findByPk(parent.ip_key)
  </code></pre>
  
  <p>everything is working, but without batcher. I suppose in my batcher I'm doing something wrong. </p>
  
  <p>Console.log shows that everything should be fine even in batcher that's why I don't understand where the problem is. Here is the console.log from batcher function of : </p>
  
  <pre><code>console.log(proxies);
  console.log(gp);
  console.log(keys.map((k) =&gt; gp[k] || []));
  
  Executing (default): SELECT `config_key`, `config_type`, `config_name`, `filename`, `member_key`, `proxy_port` FROM `config` AS `config` WHERE `config`.`config_key` = 2314;
  Executing (default): SELECT `proxy_key`, `config_key`, `ip_key` FROM `config_proxy` AS `config_proxy` WHERE `config_proxy`.`config_key` = 2314;
  Executing (default): SELECT `ip_key`, `ip_address`, `cblock_key` FROM `cblock_ip` AS `cblock_ip` WHERE `cblock_ip`.`ip_key` IN (116312, 185667, 185969, 99424);
  [ { ip_key: 99424, ip_address: '172.246.69.152', cblock_key: 576 },
    { ip_key: 116312, ip_address: '45.59.24.113', cblock_key: 645 },
    { ip_key: 185667,
      ip_address: '184.174.74.121',
      cblock_key: 1051 },
    { ip_key: 185969,
      ip_address: '184.174.75.170',
      cblock_key: 1052 } ]
  { '99424':
     [ { ip_key: 99424, ip_address: '172.246.69.152', cblock_key: 576 } ],
    '116312':
     [ { ip_key: 116312, ip_address: '45.59.24.113', cblock_key: 645 } ],
    '185667':
     [ { ip_key: 185667,
         ip_address: '184.174.74.121',
         cblock_key: 1051 } ],
    '185969':
     [ { ip_key: 185969,
         ip_address: '184.174.75.170',
         cblock_key: 1052 } ] }
  [ [ { ip_key: 116312, ip_address: '45.59.24.113', cblock_key: 645 } ],
    [ { ip_key: 185667,
        ip_address: '184.174.74.121',
        cblock_key: 1051 } ],
    [ { ip_key: 185969,
        ip_address: '184.174.75.170',
        cblock_key: 1052 } ],
    [ { ip_key: 99424, ip_address: '172.246.69.152', cblock_key: 576 } ] ]
  </code></pre>
  
  <p>and the graphql query looks like this</p>
  
  <pre><code>query Proxies($config_key: Int!) {
    config(config_key: $config_key) {
      config_name
      configProxy {
        proxy_key
        ip_key {
          ip_address
        }
      }
    }
  }
  </code></pre>