Skip to content

indexQuery does not return errors from GraphQL response (unlike list) #692

Description

@akitomonam

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

  1. 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"])])
  2. Set up an AppSync pipeline resolver that calls util.appendError() (e.g., a custom authorization resolver that appends errors for denied items)
  3. Call the index query from the frontend:
    const { data, errors } = await client.models.Todo.listTodoByOwnerIdAndStatus({
      ownerId: "user-123",
      status: { eq: "active" },
    });
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions