0

I am currently using Amplify with AppSync, and I want to grab Bs from every A item created, and populate them as an array of "items" as a result.

I searched up pipeline resolvers to deal with those, but got no luck since they are mostly based on "Grabbing all the Bs with A's ID=something", but what about ID=any.

I just want to follow the single-table architecture for DynamoDB. In this sense, how am I able to grab all the Bs?

schema.graphql:

type A @model {
  id: String!
  theBs: [B]
}

type B {
  id: ID!
  A: String!
  name: String
}

type BConnection {
  items: [B]
  nextToken: String
}

type Query {
  getBs: BConnection
}
ProgrammingFreak
  • 498
  • 3
  • 13

1 Answers1

0

Assuming you are using the generated queries, it should be something like the following. You'll need to use the nextTokens to get everything.

That being said, this will perform a scan operation in DDB, which is slow and expensive. I would recommend you read through this article about access patterns and see if there is a better way to organize your data.

query q {
      listA {
        nextToken
        items {
          theBs {
            nextToken
            items {
              id name
            }
          }
        }
      }
    }
Alex
  • 952
  • 7
  • 12
  • So in this case, would you favor multi-table design? Since for this design, A also consist of B, C and D, and in the future I would need to list out B, C and D respectively. – ProgrammingFreak Jun 02 '21 at 22:17