Skip to main content

Search from Following

Search for terms within the context of accounts you follow, prioritizing results from your social network.

Query Structure​

query SearchTermFromFollowing(
$address: String!
$query: String!
$limit: Int
) {
search_term_from_following(
args: {
address: $address
query: $query
}
limit: $limit
) {
term_id
label
image
type
creator {
label
image
}
}
}

Variables​

VariableTypeRequiredDescription
addressStringYesAccount address whose following list to use
queryStringYesSearch query text
limitIntNoMaximum results
{
"address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"query": "defi",
"limit": 10
}

Use Cases​

Search prioritizing content from your network:

async function searchInNetwork(
address: string,
searchQuery: string
) {
const gqlQuery = `
query SearchFromFollowing(
$address: String!
$query: String!
) {
network: search_term_from_following(
args: { address: $address, query: $query }
limit: 10
) {
term_id
label
image
creator { label }
}
global: search_term(
args: { query: $query }
limit: 10
) {
term_id
label
image
}
}
`

const data = await client.request(gqlQuery, {
address,
query: searchQuery
})

return {
fromNetwork: data.network,
global: data.global
}
}
function SocialSearch({ address }: { address: string }) {
const [query, setQuery] = useState('')

const { data, loading } = useQuery(SEARCH_FROM_FOLLOWING, {
variables: { address, query },
skip: query.length < 2
})

return (
<div>
<input
placeholder="Search your network..."
value={query}
onChange={(e) => setQuery(e.target.value)}
/>

<div className="results">
<h3>From Your Network</h3>
{data?.search_term_from_following.map(atom => (
<AtomCard key={atom.term_id} atom={atom} />
))}
</div>
</div>
)
}