itsjay
(Jay)
October 23, 2021, 2:52am
1
When I have multiple list fields with the same type in GraphQL schema, and one of those is empty, the query just doesn’t respond
As an example, if this is my schema:
type TestQuestion {
id: ID!
name: String!
answers: [TestAnswer] @hasInverse(field: ques)
draftAnswers: [TestAnswer]
}
type TestAnswer {
id: ID!
name: String!
ques: TestQuestion
}
And if this is the query:
query getTestQuestion($id: ID!) {
getTestQuestion(id: $id) {
id
name
draftAnswers {
id
}
answers {
id
}
}
}
when draftAnswers = null
and answers != null
the query never responds.
Some points to note:
If I put answers
before draftAnswers
it works. So, the pattern seems to be, whatever comes first in the query cannot be null (tried this by making answers null, and putting it first in the query. Also, when both fields are populated, the query works)
when none of the fields is a list, everything works fine. So this just seems to be an issue with list types.
Is there a workaround for this?
itsjay
(Jay)
October 23, 2021, 11:56pm
3
Agreed, there’s something wrong here … or maybe I’m doing something wrong.
But this the input:
{
"input": {
"name": "Question 1",
"answers": [
{
"name": "Ans 1"
},
{
"name": "Ans 2"
}
]
}
}
And this is the mutation I use to save question & ans:
mutation addTestQues($input: [AddTestQuestionInput!]!) {
addTestQuestion(input: $input) {
testQuestion {
id
}
}
}
Using the ID returned from here in the query I posted earlier causes it to fail.
And like I said, in the query, if I put answers
before draftAnswers
, it works.
itsjay
(Jay)
October 25, 2021, 6:57pm
4
Another point to add here:
If I only include draftAnswers
in the query, like:
query getTestQuestion($id: ID!) {
getTestQuestion(id: $id) {
id
name
draftAnswers {
id
}
}
}
I get the result:
"getTestQuestion": {
"id": "0x4e80",
"name": "q1",
"draftAnswers": []
}
modosc
(jonathan schatz)
October 25, 2021, 7:58pm
5
we’re seeing the same thing - i’m trying to get a repro together.
is there some logging or EXPLAIN
equivalent that we can use to diagnose this?
itsjay
(Jay)
October 25, 2021, 9:17pm
6
Looks like it’s an issue with v21.03.0.
Found these issues:
I personally would be a fan of latest being removed from docs/ docker hub, since it has completely undefined release semantics, and causes confusion like this.
Maybe this should the content of a new topic here.
And this PR:
dgraph-io:master
← dgraph-io:rajas/DGRAPH-3257
opened 05:41AM - 15 Apr 21 UTC
Motivation:
Current GraphQL encoding had a bug which led to timing out in case … there is an empty list in dataset and it is queried before any non-null field. This fixes this behaviour.
Fixes DGRAPH-3257
Testing:
1. The test times out (as expected) without the change to outputnode_graphql.go
2. The test passes with the change to outputnode_graphql.go
<!--
Your title must be in the following format: topic(Area): Feature
Topic must be one of build|ci|docs|feat|fix|perf|refactor|chore|test
Sample Titles:
feat(Enterprise): Backups can now get credentials from IAM
fix(Query): Skipping floats that cannot be Marshalled in JSON
perf: [Breaking] json encoding is now 35% faster if SIMD is present
chore: all chores/tests will be excluded from the CHANGELOG
Please add a description with these things:
1. A good description explaining the problem and what you changed.
2. If it fixes any GitHub issues, say "Fixes #GitHubIssue".
3. If it corresponds to a Jira issue, say "Fixes DGRAPH-###".
4. If this is a breaking change, please put "[Breaking]" in the title. In the description, please put a note with exactly who these changes are breaking for.
-->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dgraph-io/dgraph/7726)
<!-- Reviewable:end -->
Tried in v21.03.2 and it works (should also work in v21.03.1, but haven’t tested yet)
1 Like