cult-of-coders / grapher

Grapher: Meteor Collection Joins + Reactive GraphQL like queries
https://atmospherejs.com/cultofcoders/grapher
MIT License
275 stars 53 forks source link

Get Object/Id of last add operation of linkMany #424

Closed lukenofurther closed 4 years ago

lukenofurther commented 4 years ago

Hi,

First of, let me say this is a fantastic package. I've found a specific situation that isn't accounted for in many links.

Consider this contrived situation - adding a link from the many side to create a comment linked to a particular post:

Comments.addLinks({
  post: {
      type: 'many',
      collection: Posts,
      field: 'postId',
  },
});

Posts.addLinks({
  comments: {
      collection: Comments,
      inversedBy: 'post'
  },
});

const commentsLink = Posts.getLink(postId, 'comments');

const result = commentsLink.add({
  body: '...'
})

In this scenario, the result, the thing returned from the add function, is the link instance. I see that the other Link operations similarly return the link instance, I assume to allow chaining.

My question is, is it possible to get the document id or the document itself, of the comment that was created? I can't see a way to do it as the return from the update is never stored anywhere. This isn't as much of an issue with other link operations like set but the add operation is a particular case where it'd be useful.

Is there something I'm missing?

theodorDiaconu commented 4 years ago

Unfortunately there is no way to do that, we favored chaining. I know it's bad but maybe another fetch is required.