Im using GraphQL and DynamoDB with the adjacency list pattern, in that I am only using one table.
Say I have the schema -
type GrandParent {
id: ID!
children: [Parent]
}
type Parent {
id: ID!
children: [Child]
}
type Child {
id: ID!
}
type Query {
getGrandParent(id: ID): GrandParent
}
For dynamodb I have the following primary key structure -
for Grandparent
pk = GRANDPARENT_<id>, sk = GRANDPARENT
for Parent
pk = PARENT_<ID>, sk = GRANDPARENT_<id>
for Child
pk = CHILD_<id>, sk = PARENT_<id>
with a GSI that will invert the keys.
So, given a Grandparent ID, I can find all the Parents using the GSI, as I know the Grandparent ID, so I can do - where sk = GRANDPARENT_<id> and pk begins with PARENT_ID
which will bring me back all the Parents, but then how can I get the IDs of these parents and now go and get all the Child records? Is it possible to do multiple trips to the DB in one graphql request?