Skip to content

Commit 02481e5

Browse files
committed
refactor(search): change GraphQL client usage to $apolloClient
1 parent 051424a commit 02481e5

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

composables/useSearchNfts.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { ResultOf } from 'gql.tada'
2+
import nftListWithSearch from '~/queries/subsquid/general/nftListWithSearch'
3+
14
export default function useSearchNfts({
25
search,
36
first = 10,
@@ -10,26 +13,36 @@ export default function useSearchNfts({
1013
const { client } = usePrefix()
1114
const chainPrefix = prefix || client.value
1215

13-
const { data, refetch, loading } = useGraphql({
14-
queryPrefix: client.value,
15-
clientName: chainPrefix,
16-
queryName: 'nftListWithSearch',
17-
variables: {
18-
first,
19-
search,
20-
orderBy,
21-
denyList,
22-
offset,
23-
},
24-
options: {
25-
fetchPolicy: 'cache-first',
26-
},
27-
disabled: computed(() => !immediate),
28-
})
16+
const { $apolloClient } = useNuxtApp()
17+
const data = ref<ResultOf<typeof nftListWithSearch>>()
18+
const loading = ref(true)
19+
20+
const fetchSearch = () => {
21+
$apolloClient.query({
22+
query: nftListWithSearch,
23+
variables: {
24+
first,
25+
search,
26+
orderBy: [orderBy],
27+
denyList,
28+
offset,
29+
},
30+
context: {
31+
endpoint: chainPrefix,
32+
},
33+
}).then((res) => {
34+
data.value = res.data
35+
loading.value = false
36+
})
37+
}
38+
39+
if (immediate) {
40+
fetchSearch()
41+
}
2942

3043
return {
3144
data,
32-
refetch,
45+
refetch: fetchSearch,
3346
loading,
3447
}
3548
}

0 commit comments

Comments
 (0)