GraphQL Errors (slice bounds out of range)

Hey,
we are using GraphQL in our (React) Web App to get data from MongoDB. The whole thing is set up using Realm.
Unfortunately we get errors quering the results. And strangely this happens only occasionally (~1 out of 5 times) but will sometimes prevent our users to use our service :frowning:

Our Query looks like this:

query {
      merchants {
        name
        address {
          postalCode
          street
        }
      }
    }

And as a result we get this (sometimes):

{
  "data": {
    "merchants": [
      {
        "address": null,
        "name": "Test Merchant 1"
      },
      {
        "address": null,
        "name": "Test Merchant 2"
      },
      {
        "address": null,
        "name": "Test Merchant 3"
      }
    ]
  },
  "errors": [
    {
      "message": "runtime error: slice bounds out of range [-1:]",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "path": ["merchants", 0, "address", "postalCode"]
    },
    {
      "message": "runtime error: slice bounds out of range [-1:]",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "path": ["merchants", 1, "address", "postalCode"]
    },
    {
      "message": "runtime error: slice bounds out of range [-1:]",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "path": ["merchants", 2, "address", "postalCode"]
    }
  ]
}

We get this error even using the Realm GraphQL playground.

Any ideas why this is happening sometimes or how to avoid it?

Kind Regards :slight_smile:

1 Like

Hi Ebrima - do you have the ability to create a support ticket with MongoDB? That might be the most effective way to debug this issue.

Hi @Ebrima_Ieigh .

Did you manage to solve the issue?
I’m having the same problem, and if you can share any tips it would be much appreciated.

No not yet.
For now we just adjusted the apollo client to refetch the data once there is an error. But this can only be a temporary solution.
We have to look into this issue again soon

@Ebrima_Ieigh Did you manage to fix this issue? I am also facing exactly the same issue with the address.
I don’t know if it’s an issue on the realm side backend implementaion.

@Sumedha_Mehta1 could you please help us out here?

1 Like

Hi Folks - there is a bug ticket filed on our end and we’re investigating this issue. It certainly seems like a bug on our end. Thanks for being patient!

3 Likes

Any updates on this please?

Once thing we figured out is that at some points this Error happens on every request. A temporary “solution” to this is redeploying the realm app…
…I know not the nicest solution

Hope there will be a proper solution soon… :confused:

1 Like

This issue is a real game stopper… @Sumedha_Mehta1 , would it be possible to have an ETA on the resolution of this bug?
@Ebrima_Ieigh , when you say “redeploying the realm app” you mean deleting it and creating a new one through the CLI?

1 Like

@Bitamine No, you don’t have to delete the App. You can “just” redeploy the same version (using the UI). It’s under “MANAGE->Deployment->History”.

Best regards

Thanks @Ebrima_Ieigh , you saved my day!
I don’t know how much it will last, but after redeploying it seems to work fine 100% of times, as opposed to around 10% before.

1 Like

Hi there, redeploying the app was not working so far, so I just took a deeper look at the issue and found what is happening (“WHAT” and not “WHY”, the “WHY” must be addressed by MongoDB team, as it is clearly a bug in their graphql implementation), but in the meantime we’ll be able to workaround it in a better way than just retrying the failing queries.

The problem arises when you have embedded fields in the schema that have properties with the same name and same type (the title field). So in my case I had (Note the btm_logoPic fields with title Pic):

{
    "bsonType": "object",
    "properties": {
        [...]
        "_organizations": {
            "bsonType": "array",
            "items": {
                "bsonType": "object",
                "properties": {
                    [...]
                    "_establishments": {
                        "bsonType": "array",
                        "items": {
                            "bsonType": "object",
                            "properties": {
                                [...]
                                "btm_logoPic": {
                                    "bsonType": "object",
                                    "properties": {
                                        "_id": {
                                            "bsonType": "objectId"
                                        },
                                        "btm_filename": {
                                            "bsonType": "string"
                                        }
                                    },
                                    "title": "Pic"
                                },
                                [...]
                            },
                            "title": "OrganizationEstablishment"
                        }
                    },
                    [...]
                    "btm_logoPic": {
                        "bsonType": "object",
                        "properties": {
                            "_id": {
                                "bsonType": "objectId"
                            },
                            "btm_filename": {
                                "bsonType": "string"
                            }
                        },
                        "title": "Pic"
                    },
                    [...]
                }
            },
            "title": "UserOrganization"
        },
        [...]
    },
    "title": "GetUserDetail"
}

and changing the title “Pic” to “PicEstablishment” and “PicOrganization” respectively fixed the issue:

{
    "bsonType": "object",
    "properties": {
        [...]
        "_organizations": {
            "bsonType": "array",
            "items": {
                "bsonType": "object",
                "properties": {
                    [...]
                    "_establishments": {
                        "bsonType": "array",
                        "items": {
                            "bsonType": "object",
                            "properties": {
                                [...]
                                "btm_logoPic": {
                                    "bsonType": "object",
                                    "properties": {
                                        "_id": {
                                            "bsonType": "objectId"
                                        },
                                        "btm_filename": {
                                            "bsonType": "string"
                                        }
                                    },
                                    "title": "PicEstablishment"
                                },
                                [...]
                            },
                            "title": "OrganizationEstablishment"
                        }
                    },
                    [...]
                    "btm_logoPic": {
                        "bsonType": "object",
                        "properties": {
                            "_id": {
                                "bsonType": "objectId"
                            },
                            "btm_filename": {
                                "bsonType": "string"
                            }
                        },
                        "title": "PicOrganization"
                    },
                    [...]
                }
            },
            "title": "UserOrganization"
        },
        [...]
    },
    "title": "GetUserDetail"
}

Of course this ends on innecessary GraphQL schema duplications, but solves the annoying issue until a proper fix will be deployed.

@Ebrima_Ieigh @Paula_farrugia … and all the others, as a new user I only can mention 2 persons, regards and thanks for your collaboration, hope it helps you!

2 Likes

Nice! That helped. Thank you!

…hope that will be fixed soon

@Bitamine thanks for the solution, we tested it out and it works for us. It was a lot of changes though, which i guess would have to be changed again if this issue is ever fixed by Realm team.

Anyways we are glad that it doesn’t break anymore