title: What is the correct type to use for an ObjectId field across mongoose and GraphQL?
body: <p>Following <a href="https://www.compose.com/articles/using-graphql-with-mongodb/" rel="nofollow noreferrer">this tutorial</a>, I have a mongoose model:  (I'm using the term "Account" instead of "Todo", but it's the same thing)</p>
  
  <pre><code>const Account = mongoose.model('Account', new mongoose.Schema({
    id: mongoose.Schema.Types.ObjectId,
    name: String
  }));
  </code></pre>
  
  <p>and a GraphQLObjectType:</p>
  
  <pre><code>const AccountType = new GraphQLObjectType({
    name: 'account',
    fields: function () {
      return {
        id: {
          type: GraphQLID
        },
        name: {
          type: GraphQLString
        }
      }
    }
  });
  </code></pre>
  
  <p>and a GraphQL mutation to create one of these:</p>
  
  <pre><code>const mutationCreateType = new GraphQLObjectType({
    name: 'Mutation',
    fields: {
      add: {
        type: AccountType,
        description: 'Create new account',
        args: {
          name: {
            name: 'Account Name',
            type: new GraphQLNonNull(GraphQLString)
          }
        },
        resolve: (root, args) =&gt; {
          const newAccount = new Account({
            name: args.name
          });
  
          newAccount.id = newAccount._id;
  
          return new Promise((resolve, reject) =&gt; {
            newAccount.save(err =&gt; {
              if (err) reject(err);
              else resolve(newAccount);
            });
          });
        }
      }
    }
  })
  </code></pre>
  
  <p>After running the query:</p>
  
  <pre><code>mutation {
    add(name: "Potato")
    {
      id,
      name
    }
  }
  </code></pre>
  
  <p>in GraphiQL, I get the response:</p>
  
  <pre><code>{
    "errors": [
      {
        "message": "ID cannot represent value: { _bsontype: \"ObjectID\", id: &lt;Buffer 5b 94 eb ca e7 4f 2d 06 43 a6 92 20&gt; }",
        "locations": [
          {
            "line": 33,
            "column": 5
          }
        ],
        "path": [
          "add",
          "id"
        ]
      }
    ],
    "data": {
      "add": {
        "id": null,
        "name": "Potato"
      }
    }
  }
  </code></pre>
  
  <p>The creation of the object was successful, and I can see it in MongoDB Compass:</p>
  
  <p><a href="https://i.stack.imgur.com/NUWFM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NUWFM.png" alt="From MongoDB Compass showing created object"></a></p>
  
  <p>but there seems to be a problem reading the value.</p>
  
  <p>How compatible are <code>GraphQLID</code> and <code>mongoose.Schema.Types.ObjectId</code> ?  If they are not compatible, am I misunderstanding the tutorial, particularly it's use of:</p>
  
  <pre><code>newAccount.id = newAccount._id;
  </code></pre>
  
  <p>?  I can't tell if the error is being thrown by GraphQL, or MongoDB, or Mongoose, or something else entirely.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Any information on the error</p>
  
  <blockquote>
    <p>ID cannot represent value: { _bsontype: \"ObjectID\", id:  }</p>
  </blockquote>
  
  <p>would be <em>very</em> helpful.  I feel it's telling me it couldn't serialize a BSON object .. but then it displays it serialized.  Even knowing what tech (mongo? mongoose? graphql?) was generating the error would help.  I'm not having any luck with Google.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>This was a caused by <a href="https://github.com/graphql/graphql-js/pull/1382" rel="nofollow noreferrer">a change</a> to the graphql package introduced recently, and there is <a href="https://github.com/graphql/graphql-js/pull/1520" rel="nofollow noreferrer">a PR</a> awaiting merge which resolves it.</p>