Skip to content

Client-side data-fetching inconsistency when link field is inside a nested field  #460

@vparpoil

Description

@vparpoil

Hello,
I just found what seems like a bug : on the client, data returned by two queries can differ depending in which order the queries are called. I just build a reproduction here : https://github.com/vparpoil/grapher-bug-client-data-fetching

I have two collections with links in between them defined as such :

Link.addLinks({
    reference: {
        type: "one",
        collection: Reference,
        field: "meta.refId",
        index: true
    }
})

Reference.addLinks({
    links: {
        type: "many",
        collection: Link,
        inversedBy: 'reference'
    }
})

Then these two queries :


firstQuery = createQuery('firstQuery', {
    Reference: {
        name: 1,
        links: {
            _id: 1,
            type: 1,
        }
    }
})

secondQuery = createQuery('secondQuery', {
    Reference: {
        name: 1,
        links: {
            meta: 1
        }
    }
})

And the following data :

let refId = Reference.insert({name: "ref1"})
Link.insert({meta: {refId: refId, name: "link1"}, type: "nested"})
Link.insert({meta: {refId: refId, name: "link2"}, type: "nested"})

When querying query1 then query2, here are the results, we expect to retrieve the meta.name field of Link items from query2, but we don't :

query1 [{"_id":"HLty9SuyvHKL8eT9x","meta":{},"type":"nested"},{"_id":"mHT9aCuyb9H2r4b2h","meta":{},"type":"nested"}]
query2 [{"meta":{"refId":"Q7p2gMFbm2vbteKY7"},"_id":"HLty9SuyvHKL8eT9x"},{"meta":{"refId":"Q7p2gMFbm2vbteKY7"},"_id":"mHT9aCuyb9H2r4b2h"}]

When querying query2 only, the name is there !

query2 [{"meta":{"refId":"Q7p2gMFbm2vbteKY7","name":"link1"},"_id":"HLty9SuyvHKL8eT9x"},{"meta":{"refId":"Q7p2gMFbm2vbteKY7","name":"link2"},"_id":"mHT9aCuyb9H2r4b2h"}]

This bug is creating inconsistent behavior when developpers use the package so I believe it should be fixed. I can work on a fix for this, but I would love some feedback first.

--

After more research, it seems like this bug is present only for nested data in a mongo Document, when two queries ask for separate fields of this nested object and these two queries are subscribed using .subscribe()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions