GraphQL query does not respond when a list field is empty

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?

This doesn’t seem right. :thinking:

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.

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": []
}

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?

Looks like it’s an issue with v21.03.0.

Found these issues:

And this PR:
https://github.com/dgraph-io/dgraph/pull/7726

Tried in v21.03.2 and it works (should also work in v21.03.1, but haven’t tested yet)

1 Like