Array types in generated GraphQL schema should follow JSON schema of a collection or custom type
Hello!
Realm generates GraphQL schema that does not reflect the exact JSON schema of a collection or custom type when it comes to array fields. Generated GraphQL schema allow arrays to contain NULLs even if this is not stated in JSON schema.
For example, please see collection schema in the attachment. (Not able to insert JSON here in a readable manner)
For this schema, I expect Realm to generate following GraphQL type for my collection:
type MyCollection {
_id: ObjectId!
arrField: [String!]!
}
Please note the exclamation sign inside the square brackets. This states that the array item can only be a string, no nulls or other types are allowed - exactly what is defined in JSON schema above.
But instead, Realm generates following:
type MyCollection {
_id: ObjectId!
arrField: [String]!
}
So, it makes array element nullable, which looks like a bug and results in typecheck issues in client apps that are using generated GraphQL schema.
Related topic on forum: https://developer.mongodb.com/community/forums/t/graphql-schema-wrongly-allows-nullable-values-as-array-items/106005
I think this behavior is confirmed to be a bug there. Would be very nice to have it fixed or at least have an explicit way to make array elements not nullable.

-
Gabor commented
I know this is an old thread, but any updates here? Did you figure it out? I just encountered this same issue...