graffiti-mongoose icon indicating copy to clipboard operation
graffiti-mongoose copied to clipboard

Using Object refs in plural model query parameters?

Open zth opened this issue 8 years ago • 2 comments

Hi!

Can I somehow use object refs in plural model query parameters? For example, I have two schemas, User and Friend. Friend has a field called user which is a mongoose.Schema.Types.ObjectId referencing a User by id. However, I am not able to query all friends belonging to the user by using user: "userIdHere" in the query parameters. I tried adding indexed: true to the field in Friend pointing to the User object ref, but I still can't query user with GraphiQL.

Basically, what I'd like to do is this:

query {
  friends(exampleParam: true, user: "idToUserGoesHere") {
    id, name, exampleParam
  }
}

For reference, this is what Friend looks like:

mongoose.Schema({
  exampleParam: {
    type: Boolean,
    indexed: true,
    default: true
  },
  user: {
    type: mongoose.Schema.Types.ObjectId, ref: 'User',
    indexed: true
  }
  ...

...and what's not working is user: "idTouserGoesHere" in my query. Is there a way to do what I'm talking about?

Thanks in advance and thanks a lot for this great library!

zth avatar Feb 20 '16 16:02 zth

@zth it doesn't seem like there is the ability to do this at the moment. I'd love it as well, though!

jontonsoup avatar Feb 26 '16 21:02 jontonsoup

Hi all I don't abou you but this is really important for me. If someone could guide me through the code I'll be able to help

rturk avatar Apr 13 '16 13:04 rturk