GraphQL schema wrongly allows nullable values as array items

With JSON schema defined as such

{
  "title": "test",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "aliases": {
      "bsonType": "array",
      "items": {
        "bsonType": "string"
      }
    }
  }
}

The generated graphQL schema is:

type Test {
  _id: ObjectId
  aliases: [String]
}

I would expect

type Test {
  _id: ObjectId
  aliases: [String!]
}

Am I missing something or is it a bug?

2 Likes

Any comments? Is it a bug or am I not seeing something here?

Interesting. Looks like a bug, as both are valid JSON:

e.g. this code is valid JSON:

	"title": "test",
	"properties": {
		"_id": "12345",
		"aliases": ["foo", "bar", "baz"]
	}
}

And so is this:

{
	"title": "test",
	"properties": {
		"_id": "12345",
		"aliases": ["foo", null, "baz"]
	}
}

And I tested this against https://www.jsonschemavalidator.net/ to make sure both of these validated against the JSON schema you provided…

Hey @aleks, thanks for catching this - I work on the Realm team, and it is something we missed and are looking into resolving. Is this blocking you or your use-case at the moment?

An array with all strings should still be valid for both schemas which is the true intent of that type.

Hey @Sumedha_Mehta1!
No, it is not blocking me. It’s just messing a bit with my type checking, which is a bit of annoyance.

I assume that you are interested in getting notified of potential bugs ASAP, yet it took two weeks for a staff member to notice it. Do you have a way in which we (users) can reach out to you directly if we find some issues?

Hey @aleks - The forums are the best place to ask questions is the forum. Another place to provide feedback/improvement suggestions for the cloud side is in our feedback engine. We try to monitor both pretty closely the best we can https://feedback.mongodb.com/forums/923521-realm

MongoDB support recommended me to file a request to fix this bug. Posting link to request here for anyone coming from search: Array types in generated GraphQL schema should follow JSON schema of a collection or custom type – MongoDB Feedback Engine

2 Likes