Ecto query with json_agg in fragment

Hoping someone can help me figure out where I’m going sideways here…

Starting with this query as the basis for an Ecto version:

 select folder_id, json_agg(p.*) from folder_memberships inner join profiles p on where folder_id in (1234) group by folder_id;

I’ve got this code:

# ids=[1234]
from(p in Profile,
      join: link in FolderMembership, on: link.profile_id ==,
      select: [link.folder_id, fragment("json_agg(?) as members", p)],
      group_by: link.folder_id,
      where: link.folder_id in ^ids
|> Repo.all

And that gets me the following error:

== Compilation error on file lib/profile.ex ==
** (Ecto.Query.CompileError) variable `p` is not a valid query expression. Variables need to be explicitly interpolated in queries with ^
    (ecto) expanding macro:

I’m sure I’m missing elementary but I’m bonkered if I know what it is. I’ve tried a number of options, but all the examples I’ve been able to see do something like fragment("json_agg(?)", p.some_field), not p itself.