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

Return an empty array instead of undefined when no link items are found #472

Closed gabrielcazacu96 closed 8 months ago

gabrielcazacu96 commented 1 year ago

Issue example

import Posts from '...';
import Categories from '...';

Posts.addLinks({
    'categories': {
        type: 'many',
        collection: Categories,
        field: 'categoryIds',
    }
})

If there is a post in the db like { _id: 'postId', categoryIds: undefined } or { _id: 'postId', categoryIds: null } or { _id: 'postId', categoryIds: [] } then Posts.createQuery({ _id: 1, categories: { _id: 1 }}).fetch() would return [{ _id: 'postId' }] instead of [{ _id: 'postId', categories: [] }].

The same issue happens with inverse links