type Task {
id: ID
name: String
occurrences: [TaskOccurrence]
}
Type TaskOccurrence {
id: ID
due: DateTime
comp: DateTime
}
Right now most every Task has one TaskOccurrence. What I want to do is get the first X Tasks with their first occurrence. So my query:
{
queryTask(first: 24) {
id
name
occurrences(first: 1) {
due
comp
}
}
}
This returns my data though that within the whole dataset there is only one occurrence instead of just one occurrence for each Task. What it looks like is happening underneath is that TaskOccurrences are being queried with a limit of 1 total and then mapped back to where they go. If I remove the filter (first: 1) or increase it to (first: 24) or higher than my Task count, then I will get mostly the correct results. I could see this getting the wrong results though as some tasks eventually will have more than a single occurrence and all occurrances could belong to a single Task instead of evenly spaced out accordingly.
That’s a bit weird. @JatinDevDG can you try and reproduce this with a smaller data set which has 5 tasks and a couple of task occurrences for each task?
I found an indicator trying to reproduce this that may help lead to the bug. I believe it is in the @auth directive. Change the rule on TaskOccurrence to anything other than a query based rule and it will work.
Will produce the correct results. And matter of fact, even if I take off the (first: 4) from the top level query, the original schema and rules will still produce the wrong results.
I even changed the auth rule to a very simple query rule that did not depend on any other linked uid but only itself like:
type TaskOccurrence @auth(
query: { rule: "query { queryTaskOccurrence { id } }" }
) ...
and it still reproduces the error, FYI.
IMO, Here is what I think is going on behind the scenes:
The filters are being passed to the part of the Dgraph/Badger script that gets the available uids based upon auth rules. It makes sense to pass some of the other filter logic ahead but the first parameter should not be passed down the chain. When the auth query rule runs it gets the available TaskOccurrence's limited to the first X and then sends that back up the chain to get reattached as available uids in the graph. This limits to a total of X sub data for the entire graph instead of X nested under each level like it is without the auth query rule.
I have not looked in the source code to try to find this logic, and I really don’t have the time to do that. If this is the case though, then this could be an easy fix by stripping the first filter from being passed down to the auth query rule
@amaster507 The example was really helpful. I am able to reproduce the issue. We will look into it and have a fix soon. I think the bug is mostly related to applying the first filter at an incorrect place like you mentioned above.