-
-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Hi there. First up, nice work with this library - my team has been experimenting with it for our Graphql project and it has saved a lot of time.
We have just run into an issue with our primary key (_id) in some of our models. We are using an integer/number for _id rather than a MongoId. While this works with Model.getResolver('findById'), it doesn't work with Model.getResolver('findByIds).
I actually get a cast error when doing relations:
{ [CastError: Cast to number failed for value "00016cb0dd2f1e4b7df8d7bd" at path "_id"]
message: 'Cast to number failed for value "00016cb0dd2f1e4b7df8d7bd" at path "_id"',
name: 'CastError',
kind: 'number',
value: 00016cb0dd2f1e4b7df8d7bd,
path: '_id',
reason: undefined }
I've pinpointed the issue here:
https://github.com/nodkz/graphql-compose-mongoose/blob/master/src/resolvers/findByIds.js#L59-L60
It looks like there is a MongoId check on the id, and then it converts to a MongoId before being put into the selector query.
Is there a particular reason for this? Some flexibilty would be great - to my knowledge, Mongoose and Mongo have no issues with _id being an integer. Integers also work with findById so we assumed it would also work with findByIds.
Happy to submit a pull request, just wanted to check first :)
Many thanks
unkleho