From c0f85930d595296c6b5f98390389f1ef81ec1e9d Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 19 May 2023 23:28:48 +0100 Subject: [PATCH] feat: module graphql client --- src/components/home/HomeFeed.tsx | 1 - src/models/home.model.ts | 15 +-------------- src/models/site.model.ts | 7 +------ src/queries/graphql.ts | 6 ++++++ 4 files changed, 8 insertions(+), 21 deletions(-) create mode 100644 src/queries/graphql.ts diff --git a/src/components/home/HomeFeed.tsx b/src/components/home/HomeFeed.tsx index 010de17c..15b73510 100644 --- a/src/components/home/HomeFeed.tsx +++ b/src/components/home/HomeFeed.tsx @@ -178,7 +178,6 @@ export const HomeFeed: React.FC<{ }> = ({ noteIds, type }) => { const { t } = useTranslation("common") const searchParams = useSearchParams() - const router = useRouter() const currentCharacterId = useAccountState( (s) => s.computed.account?.characterId, diff --git a/src/models/home.model.ts b/src/models/home.model.ts index 8d470fa5..2e5fd561 100644 --- a/src/models/home.model.ts +++ b/src/models/home.model.ts @@ -1,10 +1,10 @@ import dayjs from "dayjs" import { indexer } from "@crossbell/indexer" -import { cacheExchange, createClient, fetchExchange } from "@urql/core" import { expandCrossbellNote } from "~/lib/expand-unit" import { ExpandedNote } from "~/lib/types" +import { client } from "~/queries/graphql" import filter from "../../data/filter.json" @@ -118,10 +118,6 @@ export async function getFeed({ count: 0, } } - const client = createClient({ - url: "https://indexer.crossbell.io/v1/graphql", - exchanges: [cacheExchange, fetchExchange], - }) const orString = noteIds .map( @@ -181,11 +177,6 @@ export async function getFeed({ } } case "hottest": { - const client = createClient({ - url: "https://indexer.crossbell.io/v1/graphql", - exchanges: [cacheExchange, fetchExchange], - }) - let time if (daysInterval) { time = dayjs().subtract(daysInterval, "day").toISOString() @@ -330,10 +321,6 @@ export async function getFeed({ } export const getShowcase = async () => { - const client = createClient({ - url: "https://indexer.crossbell.io/v1/graphql", - exchanges: [cacheExchange, fetchExchange], - }) const oneMonthAgo = dayjs().subtract(10, "day").toISOString() const listResponse = await client diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 0f17832b..7bdcc910 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -4,10 +4,10 @@ import type { Address } from "viem" import type { useContract } from "@crossbell/contract" import { indexer } from "@crossbell/indexer" -import { cacheExchange, createClient, fetchExchange } from "@urql/core" import { expandCrossbellCharacter } from "~/lib/expand-unit" import { SiteNavigationItem } from "~/lib/types" +import { client } from "~/queries/graphql" type Contract = ReturnType @@ -32,11 +32,6 @@ export const getSubscriptionsFromList = async ( list: number[], fromCharacterId: number, ) => { - const client = createClient({ - url: "https://indexer.crossbell.io/v1/graphql", - exchanges: [cacheExchange, fetchExchange], - }) - const response = await client .query( ` diff --git a/src/queries/graphql.ts b/src/queries/graphql.ts new file mode 100644 index 00000000..c2e23da6 --- /dev/null +++ b/src/queries/graphql.ts @@ -0,0 +1,6 @@ +import { cacheExchange, createClient, fetchExchange } from "@urql/core" + +export const client = createClient({ + url: "https://indexer.crossbell.io/v1/graphql", + exchanges: [cacheExchange, fetchExchange], +})