toeverything/AFFiNE · error · QueryTooLong

query_too_long

query_too_long

Error message

Query is too long, max length is ${max}.

What it means

Thrown by the members resolver when the optional query argument exceeds 255 characters. The member search is bounded to keep query cost predictable; longer strings are rejected before hitting the workspaceUser.search model. Reported with code query_too_long (HTTP 400, invalid_input).

Source

Thrown at packages/backend/server/src/core/workspaces/resolvers/member.ts:200

  @ResolveField(() => [InviteUserType], {
    description: 'Members of workspace',
    complexity: 2,
  })
  async members(
    @CurrentUser() user: CurrentUser,
    @Parent() workspace: WorkspaceType,
    @Args('skip', { type: () => Int, nullable: true }) skip?: number,
    @Args('take', { type: () => Int, nullable: true }) take?: number,
    @Args('query', { type: () => String, nullable: true }) query?: string
  ) {
    await this.ac
      .user(user.id)
      .workspace(workspace.id)
      .assert('Workspace.Users.Read');

    if (query) {
      if (query.length > 255) {
        throw new QueryTooLong({ max: 255 });
      }

      const list = await this.models.workspaceUser.search(workspace.id, query, {
        offset: skip ?? 0,
        first: take ?? 8,
      });

      return list.map(({ status, type, user }) => ({
        ...user,
        permission: Number(type),
        role: Number(type),
        inviteId: user?.id ?? '',
        status,
      }));
    } else {
      const [list] = await this.models.workspaceUser.paginate(workspace.id, {
        offset: skip ?? 0,
        first: take ?? 8,

View on GitHub (pinned to 26c515e050)

Solutions

  1. Truncate the query to <= 255 characters before sending the GraphQL request.
  2. Add maxlength=255 (and client truncation) to the member-search input.
  3. If you need member filtering by multiple emails, use a different/batched API rather than one long query.

Example fix

// before
members(workspace, { query: longString });
// after
members(workspace, { query: longString.slice(0, 255) });
Defensive patterns

Strategy: validation

Validate before calling

const MAX_QUERY = 255;
function sanitizeMemberQuery(q: string | undefined): string | undefined {
  if (!q) return q;
  return q.length > MAX_QUERY ? q.slice(0, MAX_QUERY) : q;
}
// before the query
const q = sanitizeMemberQuery(rawQuery);

Type guard

function isWithinQueryLimit(q: string | undefined, max = 255): boolean {
  return !q || q.length <= max;
}

Prevention

When it happens

Trigger: Querying the members field of a workspace with a query string longer than 255 characters.

Common situations: A search box bound directly to the query arg without a max-length attribute; pasting a long blob/email list into the member search; a debounced search that accumulates whitespace.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/01a2b422fa62f6a9. Report an issue: GitHub.