I get the following error: "Field 'images' is required and cannot be 'null'
From what I’ve read, an empty array is not considered null and should be valid for the [Image!]!. In short: why can’t I pass an empty array for the images property?
On a similar note, I noticed the graphql type for allListings is the following:
having empty array if fine, but in your case you specify as:
type Listing {
address: String!
images: [Image!]!
zipCode: String!
}
in that case, an empty array violates the directive. The ! force to return at least one value/element and an empty array is not valid then.
You can try this way:
type Listing {
address: String!
images: [Image]
zipCode: String!
}
to remove such constraint.
For your second question, this way
Hi @bez,
Just checked internally, and even if the solution I provided actually works, also your should.
We already have a bug open for this, and we are working on fixing it.
Sorry for the inconvenient.
[Episode!]! represents an array of Episode objects. Since it is also non-nullable , you can always expect an array (with zero or more items) when you query the appearsIn field. And since Episode! is also non-nullable , you can always expect every item of the array to be an Episode object.
In other words, [Image!]! does not mean that the array has to have at least one item. It just means that none of the items in the array will be null. Therefor an empty array should pass the graphql validation.
Am I understanding correctly? If so, is this a known deviation from the graphql spec?
@Luigi_Servini I just saw your second comment. Thanks for the update. Is there anywhere where we can track the progress of issues? I guess something similar to GitHub issues?
At the moment, to my knowledge, we don’t have such a process in place. We do sometimes give out the ticket number to the user, so they can ask later on whether something has changed on this. However, I ticketed this fairly recently after receiving this user feedback (PROD-827) since I personally assume this is an inconsistency and assume that we can do better. That opinion is not yet confirmed by engineering and it’s not prioritized yet. That should give you an idea on whether you want to wait for it or adapt your queries. Given that there is a workaround I would personally not wait for it.
Has this issue been resolved? I believe I am experiencing the same inconsistency with my GraphQL schema implementation: [Type!]! field being set to throws “is required and cannot be ‘null’”