Describe the bug
The indexQuery implementation in packages/data-schema/src/runtime/internals/operations/indexQuery.ts does not include the errors field in its return value, while the equivalent list.ts implementation does.
When a GraphQL response contains both data and errors (e.g., partial errors from AppSync pipeline resolvers using util.appendError()), the list operation correctly returns { data, nextToken, errors }, but indexQuery only returns { data, nextToken } — silently dropping the errors.
We would like to understand whether this is an intentional design decision or an unintended omission. If intentional, could you explain the reasoning behind the difference in behavior between list and indexQuery?
Affected code (indexQuery.ts L200-224):
// errors is destructured but never included in the return value
const { data, errors } = error;
if (data[key]?.items) {
const flattenedResult = ...;
if (flattenedResult) {
return {
data: args?.selectionSet ? flattenedResult : modelInitializer(flattenedResult),
nextToken: data[key]?.nextToken,
// ❌ missing: errors
};
}
}
return {
data: data[key],
nextToken: data[key]?.nextToken,
// ❌ missing: errors
};
Corresponding code (list.ts L195-227):
const { data, errors } = error;
if (data[key]?.items) {
const flattenedResult = ...;
if (flattenedResult) {
return {
data: flattenedResult,
nextToken: data[key]?.nextToken,
errors, // ✅ included
};
}
}
The same inconsistency also exists in processGraphQlResponse() (the happy path) — it returns { data, nextToken, extensions } but does not return errors.
To Reproduce
- Define a model with a secondary index:
Todo: a
.model({ title: a.string(), ownerId: a.id().required(), status: a.string() })
.secondaryIndexes((index) => [index("ownerId").sortKeys(["status"])])
- Set up an AppSync pipeline resolver that calls
util.appendError() (e.g., a custom authorization resolver that appends errors for denied items)
- Call the index query from the frontend:
const { data, errors } = await client.models.Todo.listTodoByOwnerIdAndStatus({
ownerId: "user-123",
status: { eq: "active" },
});
errors is always undefined, even when the GraphQL response contains errors
Expected behavior
errors should be returned from index query operations, consistent with the list operation behavior. The return value should be { data, nextToken, errors }.
Desktop (please complete the following information)
- OS: macOS
@aws-amplify/data-schema: 1.21.0
aws-amplify: ^6.15.3
Additional context
This affects any use case where AppSync resolvers use util.appendError() with secondary index queries. In our case, custom authorization pipeline resolvers use util.appendError() to notify the frontend about access control errors, but these errors are silently dropped when the query goes through indexQuery.
Would it be reasonable to add errors to the return statements in indexQuery.ts to match the behavior of list.ts? If there is a specific reason for the current behavior, we would appreciate guidance on the recommended way to handle errors from index queries on the client side.
Describe the bug
The
indexQueryimplementation inpackages/data-schema/src/runtime/internals/operations/indexQuery.tsdoes not include theerrorsfield in its return value, while the equivalentlist.tsimplementation does.When a GraphQL response contains both
dataanderrors(e.g., partial errors from AppSync pipeline resolvers usingutil.appendError()), thelistoperation correctly returns{ data, nextToken, errors }, butindexQueryonly returns{ data, nextToken }— silently dropping the errors.We would like to understand whether this is an intentional design decision or an unintended omission. If intentional, could you explain the reasoning behind the difference in behavior between
listandindexQuery?Affected code (
indexQuery.tsL200-224):Corresponding code (
list.tsL195-227):The same inconsistency also exists in
processGraphQlResponse()(the happy path) — it returns{ data, nextToken, extensions }but does not returnerrors.To Reproduce
util.appendError()(e.g., a custom authorization resolver that appends errors for denied items)errorsis alwaysundefined, even when the GraphQL response contains errorsExpected behavior
errorsshould be returned from index query operations, consistent with thelistoperation behavior. The return value should be{ data, nextToken, errors }.Desktop (please complete the following information)
@aws-amplify/data-schema: 1.21.0aws-amplify: ^6.15.3Additional context
This affects any use case where AppSync resolvers use
util.appendError()with secondary index queries. In our case, custom authorization pipeline resolvers useutil.appendError()to notify the frontend about access control errors, but these errors are silently dropped when the query goes throughindexQuery.Would it be reasonable to add
errorsto the return statements inindexQuery.tsto match the behavior oflist.ts? If there is a specific reason for the current behavior, we would appreciate guidance on the recommended way to handle errors from index queries on the client side.