Problem
I am implementing cursor-based pagination in graphql in AWS appsync schema. I want to restrict the type depending on query. For example, getBuildingsBySite should not allow any type other than Building. Currently, it allows all types in the Union. How can this be achieved?
type Site {
siteName: String
address: String
siteId: String!
sitePicture: String
siteImgUrl: String
}
type Floor {
floorName: String
accessPointsCount: Int
unitsCount: Int
wingName: String
floorId: String!
}
type Building {
buildingId: String!
buildingName: String
buildingAddress: String
buildingImgUrl: String
buildingImg: String
}
type PageInfo {
hasNextPage: Boolean
endCursor: Boolean
}
type Collection {
edges: Edge
pageInfo: PageInfo
}
type Edge {
node: [Node]
cursor: String
}
union Node = Site | Building | Floor
type Query {
getSites(first: Int, cursor: String): Collection
getBuildingsBySite(first: Int, cursor: String, siteId: String!): Collection
getFloorsByBuilding(first: Int, cursor: String, siteId: String!, buildingId: String!): Collection
}
Query
{
getBuildingsBySite(first: 10, cursor: "xyz", siteId: "S1") {
edges {
node {
... on Site {
siteName
address
address
}
... on Building {
buildingId
buildingName
}
... on Floor {
floorId
floorName
}
}
}
}
}
If any better approach exists in AWS Appsync for pagination, please suggest it. Thanks