Closed
Description
I recently updated from 0.13.2
to 14.0.2
which includes breaking changes.
This introduced errors with existing queries which include MongoDB Object Ids (probably from #1382):
ID cannot represent value: { _bsontype: "ObjectID", id: <Buffer 5b 96 3d bf 98 0a 04 09 85 c6 6e a1> }
Repository with complete, minimal repeatable example here:
const Thing = mongoose.model('Thing', new mongoose.Schema({
id: mongoose.Schema.Types.ObjectId,
name: String
}));
const ThingType = new GraphQLObjectType({
name: 'thing',
fields: function () {
return {
id: { type: GraphQLID },
name: { type: GraphQLString }
}
}
});
const RootMutation = new GraphQLObjectType({
name: 'CreateMutation',
fields: {
create: {
type: ThingType,
description: 'Create new thing',
args: {
name: {
name: 'Name of Thing',
type: new GraphQLNonNull(GraphQLString)
}
},
resolve: (root, args) => {
const newThing = new Thing({ name: args.name });
newThing.id = newThing._id;
return new Promise((res, rej) => {
newThing.save(err => {
if (err) return rej(err);
res(newThing);
});
});
}
}
}
});
Metadata
Metadata
Assignees
Labels
No labels