Search Positions on Subject
Search for positions (stakes) related to a specific subject. This function takes an array of addresses and a JSONB search fields object to filter positions.
Query Structureβ
query SearchPositionsOnSubject(
$addresses: _text!
$searchFields: jsonb!
$limit: Int
) {
search_positions_on_subject(
args: {
addresses: $addresses
search_fields: $searchFields
}
limit: $limit
order_by: { shares: desc }
) {
id
account_id
account {
label
image
}
shares
created_at
vault {
term_id
triple {
predicate { label }
object { label }
}
}
}
}
Variablesβ
| Variable | Type | Required | Description |
|---|---|---|---|
addresses | _text | Yes | PostgreSQL text array of account addresses to search |
search_fields | jsonb | Yes | JSONB object specifying search criteria |
limit | Int | No | Maximum results |
{
"addresses": "{0xd8da6bf26964af9d7eed9e03e53415d37aa96045}",
"searchFields": {},
"limit": 20
}
note
The addresses parameter uses PostgreSQL's _text array format: {addr1,addr2} (curly braces, comma-separated, no quotes within the braces).
Response Fieldsβ
The function returns position rows, so all position fields are available:
| Field | Type | Description |
|---|---|---|
id | String | Position identifier |
account_id | String | Account holding position |
account | accounts | Account details (relationship) |
shares | numeric | Shares held |
created_at | timestamptz | Position creation time |
vault | vaults | Associated vault (relationship) |
Use Casesβ
Find Who Believes Somethingβ
See all positions from specific accounts:
async function getPositionsForAccounts(addresses: string[]) {
const query = `
query GetPositions($addresses: _text!, $searchFields: jsonb!) {
search_positions_on_subject(
args: {
addresses: $addresses
search_fields: $searchFields
}
order_by: { shares: desc }
limit: 50
) {
account {
id
label
image
}
vault {
triple {
predicate { label }
object { label }
}
}
shares
}
}
`
// Format as PostgreSQL text array
const pgArray = `{${addresses.join(',')}}`
const data = await client.request(query, {
addresses: pgArray,
searchFields: {}
})
return data.search_positions_on_subject
}
Best Practicesβ
- Order by shares - Show most-supported positions first
- Group results - Aggregate positions by claim
- Show supporter count - Indicate social proof
- Link to profiles - Make supporters clickable
Relatedβ
- Search Term - Search atoms by text
- User Positions - Account position queries