RisingStack / graffiti-mongoose

⚠️ DEVELOPMENT DISCONTINUED - Mongoose (MongoDB) adapter for graffiti (Node.js GraphQL ORM)
https://risingstack-graffiti.signup.team/
MIT License
382 stars 52 forks source link

Mongoose ObjectId and GraphQL id is not the same. How to link them? #207

Closed tedchsk closed 5 years ago

tedchsk commented 7 years ago

I am quite new to GraphQL, and I am quite confuse with the concept. My Mongoose ObjectId and GraphQL id is not the same. How can I use Id from Mongoose can find that Object through graphQL and vice versa? Or do I only have to create new field to link the two?

This is my mongoose schema. const userSchema = new Schema({ name: String, email: String, password: String, permission_level: Number, validation_code : String, not_validate:Boolean, facebook : { id : String, token : String, email : String, name : String }, omise_cusid: String });

jashmenn commented 7 years ago

Hey @Teerapat12! So this is actually by design. The GraphQL ID encodes the type of the object, as well as the mongodb ID.

tedchsk commented 7 years ago

Does GraphQL have anyway of decoding the ID to become MongodbID?

tedchsk commented 7 years ago

I think I got it now. Thank you very much. :D

tedchsk commented 7 years ago

More questions. -So why does GraphQL need to encode the type of the object? -What is the advantage of this? -And if I have a mongoose UserId, how can I fetch that User but instead of mongoose, I use GraphQL instead? Or do I only have to use GraphQL

Thank you in advanced. I really want to master GraphQL. :D

tedchsk commented 5 years ago

(Why did I get the thumbsdown? What did I do wrong)