Skip to content

Query Driven sync doesn't pass filters when being used in includes #1441

Description

@parthverma1
  • I've validated the bug against the latest version of DB packages

Describe the bug
When using the nested UI queries as announced here, the where clause is not passed to the queryFn via loadSubsetOptions. This means all the data needs to be fetched thus eliminating the benefits of partial data fetching.

To Reproduce

const root = createCollection(
  queryCollectionOptions({
    queryKey: ['root'],
    syncMode: 'on-demand',
    queryFn: async (context) => {
      return getRoots();
    },
    queryClient,
    getKey: (item) => item.id,
  })
);

const items = createCollection(
  queryCollectionOptions({
    queryKey: ['root-items'],
    syncMode: 'on-demand',
    queryFn: async (context) => {
      const { filters } = parseLoadSubsetOptions(
        context.meta?.loadSubsetOptions
      );
      const rootId = filters[0].value; // <- This is never defined
      const items = await getRootItems(filters[0].value)
    },
    queryClient,
    getKey: (item) => item.id,
  })
);


const collection = await queryOnce((q) => {
  const c = q
    .from({ r: root })
    .select(({ r }) => ({
      id: collection.id,
      name: collection.title,
      children: toArray(
        q
          .from({ items: items })
          .where(({ items }) => eq(items.rootId, r.id))
          .select(({ items }) => ({
            id: items.id,
            type: items.type,
            name: items.title,
          }))
      ),
    }));
  return c;
});

Expected behavior
rootId should be defined in the queryFn

Desktop (please complete the following information):

  • OS: [e.g. iOS]: macOS Tahoe 26.2
  • Browser [e.g. chrome, safari]: chrome
  • Version [e.g. 22]: 146.0.7680.167

Additional context
Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions