Here’s my schema:
type Post
@model {
createdAt: AWSDateTime!
hash: String!
version: Int
@default(value: "0")
@index(name: "byVersion", sortKeyFields: ["createdAt"])
}
Here’s the generated query that AWS Amplify generates:
export const postsByVersionAndCreatedAt = /* GraphQL */ `
query postsByVersionAndCreatedAt(
$version: Int!
$createdAt: ModelStringKeyConditionInput
$sortDirection: ModelSortDirection
$filter: ModelPiecePostFilterInput
$limit: Int
$nextToken: String
) {
postsByVersionAndCreatedAt(
version: $version
createdAt: $createdAt
sortDirection: $sortDirection
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
hash
id
version
__typename
}
nextToken
__typename
}
}
`;
Finally, here’s my attempt to retrieve the first 10 items:
const postsByVersionAndCreatedAtResult = await API.graphql({
authMode: GRAPHQL_AUTH_MODE.AWS_IAM,
query: postsByVersionAndCreatedAt,
variables: {
filter: {
hash: {
beginsWith: e.target.value,
},
},
limit: 10,
sortDirection: "DESC",
version: 0,
},
});
This works, but I only get 3 items, not 10 items. I thought creating an @index
in the schema would solve this problem, but it doesn’t! What must I do/change?