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.
Hi all,
We recently announced that we have decided to deprecate the Atlas GraphQL API, and current users should’ve received an email explaining the details of the deprecation and end-of-life plan. Consequently, we will not be adding new features going forward and are updating the status for all related feedback accordingly.
Please read our announcement in the MongoDB Developer Center for more details and guidance on the migration process and timeline. Should you have any questions or need further assistance, please reach out to our support team via the MongoDB Support Portal.
We truly prioritize your satisfaction and success, and we thank you for your patience and the feedback you have provided us over the years.
-
Fabien commented
Hello,
Please could you give us a good way to fix this kinds of issue ?
No update since 3 years, should we manually update graphql schema to include [Type!]! for array ??
Is there another clean way to do that ?
Thanks !
-
Gabor commented
I know this is an old thread, but any updates here? Did you figure it out? I just encountered this same issue...