Appsync GSI not producing existing DynamoDB record by Graphql using amplify

0

I've used Amplify to generate AppSync schema and GraphQL resolvers automatically. All of sudden, a major fetch stopped working. This is the query that I am running in the AppSync console:

query CreamByUuid {
  creamByUUID(streamUUID: "6e1a5555-9999-6666-84c1-54e777777777", id: {}) {
    items {
      id
    }
    nextToken
  }
  milkBySlug(slug: "cherry-rare-solo-appearance") {
    nextToken
    items {
      price
      id
    }
  }
  getCream(id: "77bababa-8888-3333-bb2b-857c470d5555") {
    id
    creamUUID
  }
}

The first part is a GSI that fetches a stream by a field called the “creamUUID”. The problem is, the result returns an empty array:

{
  "data": {
    "creamByUUID": {
      "items": [],
      "nextToken": null
    },
    "milkBySlug": {
      "nextToken": null,
      "items": [
        {
          "price": 7,
          "id": "17e50e71-ay7d-8382-1098-25c616444444"
        }
      ]
    },
    "getCream": {
      "id": "77bababa-8888-3333-bb2b-857c470d5555",
      "creamUUID": "6e1a5555-9999-6666-84c1-54e777777777"
    },
  }
}

I’ve tested another GSI, milkBySlug, to make sure it’s not a broader GSI issue. As you see though, I am correctly getting an item back.

More troubling, when I fetch the Cream by its ID, I actually get the Cream record back (“getCream” returns the record with a creamUUID of “6e1a5555-9999-6666-84c1-54e777777777”)

So the Cream record exists in DynamoDB, and a direct query of it using an ID returns it. But a GSI creamByUUID with the creamUUID returns an empty array.

The resolver is autogenerated by amplify push, and I can share that if it is helpful. The queries I’m making are directly within the AWS console, so it can’t be a coding error on my part…

Can anyone help? I'm out of ideas about why the creamByUUID returns an empty array when it should return the Cream record with ID 77bababa-8888-3333-bb2b-857c470d5555

1 個回答
1
已接受的答案

For anyone that experiences this issue, it's because I duplicated the GSIs on a new schema I created recently. I removed the GSIs on the new schema and things are working again!

The problem though is that amplify should not have let me add the new schema with duplicate GSIs. This is definitely a bug that should be looked at @aws

已回答 2 年前
  • Thanks for this heads up - in my case I couldn't figure out why some queries would return an empty array, while others would return partial data, it made no sense at all. Removing a GSI on a different model, that had the same @key name and queryfield fixed the problem.

    I agree that amplify should warn the user!

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南