-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to query for MongoDB ObjectIDs #1518
Comments
Background: I'm a learner. Following this tutorial I encountered this problem which was very confusing trying to debug. It would be nice if there was perhaps a clearer error message ( |
@alexmcmillan Thanks for detail description and especially example repo 👍
Problem is that you can define GraphQL types in SDL without working directly with type thing {
id: ID
name: String
} So we can't use
We can't have |
@IvanGoncharov that makes perfect sense, thank you for your clear explanations here. Hope your solution gets merged soon so I can come forward to v14 :) |
any changes this gets into 14.0.3? |
Yes, I am still stuck using '^0.13.2' as the latest '^14.0.2' continues to give me these issues. |
I would also like to know if it has been fixed for the I tested the version |
@RadAcademy @GlauberF We plan to include it into the next release. |
This comment has been minimized.
This comment has been minimized.
oh thanks, when you are at your first steps like me , nosebleeds are ruff. |
@alexmcmillan @sibelius @RadAcademy @GlauberF @axe-z I went ahead and merged #1520. |
This comment has been minimized.
This comment has been minimized.
I had the same issue, i resolved this issue by writing this code in the types definition file of graphql
|
should this be done on @vkarpov15 does it make sense to |
@sibelius not a bad idea. Opened up a mongoose issue to track this |
@vkarpov15 tks, keep the good work |
fix Automattic#7299 fix graphql/graphql-js#1518 this make interop of ObjectId and GraphQL easier
still not fixed? |
I don't use graphql so I'm not certain whether this is fixed, but this might help: http://thecodebarbarian.com/whats-new-in-mongoose-54-global-schematype-configuration.html |
@infinitegachi try to use this mongoose PR Automattic/mongoose#7353 |
I've made a field resolver to help on this import { GraphQLNonNull, GraphQLString } from 'graphql';
import { Types } from 'mongoose';
export const mongooseIDResolver = {
_id: {
type: GraphQLNonNull(GraphQLString),
description: 'mongoose _id',
resolve: ({ _id }: { _id: Types.ObjectId}) => ({ _id: _id.toString() }),
},
}; so if you want to expose an _id in your GraphQL, you need a custom type or transform ObjectId to string |
@sibelius just FYI, Mongoose does not support |
Types.ObjectId is for typechecking only I guess |
I believe this is fixed in ^14.2.1 and mongoose ^5.4.20 |
I recently updated from
0.13.2
to14.0.2
which includes breaking changes.This introduced errors with existing queries which include MongoDB Object Ids (probably from #1382):
Repository with complete, minimal repeatable example here:
The text was updated successfully, but these errors were encountered: