Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vparpoil opened this issue Feb 9, 2022 · 0 comments

Comments

@vparpoil
Copy link
Contributor

vparpoil commented Feb 9, 2022

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant