title: GraphQL cyclical reference using thunks - Error: field type must be Output Type but got: undefined
body: <p>I have to solve a cyclic definition for GraphQL, but for some reason I´m not being able to solve. I´ve checked several posts about thunks and lazy loading and here is my current code:</p>
  
  <p><strong>History/types.js</strong></p>
  
  <pre><code>const fields = {
      id: {
          type: new GraphQLNonNull(GraphQLID),
          resolve: (obj) =&gt; dbIdToNodeId(obj._id, "History")
      },
      timestamp: {
          type: GraphQLLong
      },
      objectId: {
          type: GraphQLString
      },
      user: {
          type: require('../User/connections').default,
          args: connectionArgs,
          resolve: (source, args) =&gt; {
              return UserModel.findOne({ id: source.id }).exec();
          }
      },
      action: {
          type: new GraphQLNonNull(GraphQLString)
      }
  };
  
  export const HistoryType = new GraphQLObjectType({
      name: 'History',
      description: 'History',
      interfaces: () =&gt; [NodeInterface],
      isTypeOf: (value) =&gt; value instanceof HistoryModel,
      fields: () =&gt; (fields)
  });
  </code></pre>
  
  <p><strong>History/connections.js:</strong></p>
  
  <pre><code>import { HistoryType } from './types';
  const { connectionType: HistoryConnectionType } = connectionDefinitions( { nodeType: HistoryType });
  
  export default HistoryConnectionType;
  </code></pre>
  
  <p><strong>User/types.js</strong></p>
  
  <pre><code>const fields = {
      id: {
          type: new GraphQLNonNull(GraphQLID),
          resolve: (obj) =&gt; dbIdToNodeId(obj._id, "User")
      },
      email: {
          type: GraphQLString
      },
      history: {
          type: require('../History/connections').default,
          args: connectionArgs,
          resolve: (source, args, context) =&gt; {
              return HistoryModel.find({ deleted: false, objectId: source.id}).sort('timestamp').exec();
          }
      }
  };
  
  export const UserType = new GraphQLObjectType({
      name: 'User',
      description: 'User',
      interfaces: () =&gt; [NodeInterface],
      isTypeOf: (value) =&gt; value instanceof UserModel,
      fields: () =&gt; (fields)
  });
  </code></pre>
  
  <p><strong>User/connections.js</strong></p>
  
  <pre><code>import { UserType } from './types';
  
  const { connectionType: UserConnectionType } = connectionDefinitions( { nodeType: UserType });
  
  export default UserConnectionType;
  </code></pre>
  
  <p><strong>Company/types.js</strong></p>
  
  <pre><code>const fields = {
      id: {
          type: new GraphQLNonNull(GraphQLID),
          resolve: (obj) =&gt; dbIdToNodeId(obj._id, "Company")
      },
      name: {
          type: GraphQLString
      },
      users: {
          type: require('../User/connections').default,
          args: connectionArgs,
          resolve: (source, args) =&gt; {
              const { id } = source;
              return UserModel.find({ companyId: id }).then((rows) =&gt; connectionFromArray(rows,args));
          }
      },
      history: {
          type: require('../History/connections').default,
          args: connectionArgs,
          resolve(source, args, context) {
              return loaders.getHistory(source.id);
          }
      }
  };
  
  export const CompanyType = new GraphQLObjectType({
      name: 'Company',
      description: 'Company',
      interfaces: () =&gt; [NodeInterface],
      isTypeOf: (value) =&gt; value instanceof CompanyModel,
      fields: () =&gt; (fields)
  });
  </code></pre>
  
  <p><strong>Company/connections.js</strong></p>
  
  <pre><code>import { CompanyType } from './types';
  
  const { connectionType: CompanyConnectionType } = connectionDefinitions( { nodeType: CompanyType });
  
  export default CompanyConnectionType;
  </code></pre>
  
  <p>I can´t make it work. When running I´m getting the following output:</p>
  
  <pre><code> History.user field type must be Output Type but got: undefined
  </code></pre>