Can't query field when schema contains nested arrays

Hi,

I’ve been struggling with an issue with my schema that contains arrays of arrays. While the schema validates, I always get an error Cannot query field \"events\" on type \"MyFieldType".

I’m trying to use this:

"events": {
                    "bsonType": "array",
                    "items": {
                      "bsonType": "array",
                      "items": {
                        "bsonType": "string"
                      }
                    }
                  }

The raw data for this looks as expected e.g.:

"events" : [
                        [
                            "101",
                            "404",
                            "625"
                        ]
                    ]

Is the issue here nested arrays, are they not supported? Note that the schema generator also produces this output.

This should have been posted in the Atlas GraphQL API section (I can’t edit it)

So for anyone else with this issue, I guess this isn’t possible despite the schema generator producing this output.

Simplified by creating a new collection and added this document:

{
    "_id" : ObjectId("633603c8a4e9837b18a0459d"),
    "events" : [
        [
            "101",
            "404",
            "625"
        ],
        [
            "201",
            "204",
            "225"
        ]
    ]
}

Then used the following GraphQL schema generator, which generated this schema:

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

While this works;

query MyQuery {
  test {
    _id
  }
}

This query:

query MyQuery {
  test {
    _id,
    events
  }
}

returns "message": "Cannot query field \"events\" on type \"Test\".",

Hi @Gareth_Davies, welcome to the community. :wave:
Querying arrays of arrays using the Atlas GraphQL API is not supported as of now. We already have a feature request logged in for this. Please upvote the same if you’d like to have this in our GraphQL API.

However, for now you can create a custom resolver to achieve the same that resolves the request to an array you expect.
Here’s a step-by-step tutorial that elaborates the complete process of creating a custom resolver:

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.