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!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠