Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache GraphQL Queries #508

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/site/gql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const client = new GraphQLClient(
headers: {
'Content-Type': 'application/json',
},
fetch,
},
)

Expand Down
5 changes: 3 additions & 2 deletions apps/site/gql/requests/getAllAdds.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export const getAllAdds = async () => {
export const getAllAdds = unstable_cache(async () => {
const response = await sdk.allAdds()

return {
adds: response.addss,
}
}
}, ['allAdds'])
5 changes: 3 additions & 2 deletions apps/site/gql/requests/getAllChannels.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export const getAllChannels = async () => {
export const getAllChannels = unstable_cache(async () => {
const response = await sdk.allChannels()

return {
channels: response.channels,
}
}
}, ['allChannels'])
5 changes: 3 additions & 2 deletions apps/site/gql/requests/getAllItems.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export const getAllItems = async () => {
export const getAllItems = unstable_cache(async () => {
const response = await sdk.allItems()

return {
items: response.items,
}
}
}, ['allItems'])
5 changes: 3 additions & 2 deletions apps/site/gql/requests/getAllUsers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export const getAllUsers = async () => {
export const getAllUsers = unstable_cache(async () => {
const response = await sdk.allUsers()

return {
users: response.users,
}
}
}, ['allUsers'])
16 changes: 10 additions & 6 deletions apps/site/gql/requests/getChannelWithId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export async function getChannelWithId({ id }: { id: string }) {
const response = await sdk.channelWithId({
id: id,
})
export const getChannelWithId = unstable_cache(
async ({ id }: { id: string }) => {
const response = await sdk.channelWithId({
id: id,
})

return { channel: response.channel }
}
return { channel: response.channel }
},
['channelWithId'],
)
16 changes: 10 additions & 6 deletions apps/site/gql/requests/getChannelsItemsWithUser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export async function getChannelsItemsWithUser({ userId }: { userId: string }) {
const response = await sdk.channelsItemsWithUser({
userId: BigInt(userId),
})
export const getChannelsItemsWithUser = unstable_cache(
async ({ userId }: { userId: string }) => {
const response = await sdk.channelsItemsWithUser({
userId: BigInt(userId),
})

return { channels: response.channels, items: response.items }
}
return { channels: response.channels, items: response.items }
},
['channelsItemsWithUser'],
)
16 changes: 10 additions & 6 deletions apps/site/gql/requests/getItemWithId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export async function getItemWithId({ id }: { id: string }) {
const response = await sdk.itemWithId({
id: id,
})
export const getItemWithId = unstable_cache(
async ({ id }: { id: string }) => {
const response = await sdk.itemWithId({
id: id,
})

return { item: response.item }
}
return { item: response.item }
},
['itemWithId'],
)
5 changes: 3 additions & 2 deletions apps/site/gql/requests/getMarqueeData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export async function getMarqueeData() {
export const getMarqueeData = unstable_cache(async () => {
const response = await sdk.marqueeData()

return {
users: response.userCounters,
channels: response.channelCounters,
items: response.itemCounters,
}
}
}, ['marqueeData'])
16 changes: 10 additions & 6 deletions apps/site/gql/requests/getTxnHash.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sdk from '../client'
import { unstable_cache } from 'next/cache'

export async function getTxnWithHash({ hash }: { hash: string }) {
const response = await sdk.txnHash({
hash: hash,
})
export const getTxnWithHash = unstable_cache(
async ({ hash }: { hash: string }) => {
const response = await sdk.txnHash({
hash: hash,
})

return { txn: response.txn }
}
return { txn: response.txn }
},
['txnHash'],
)
2 changes: 1 addition & 1 deletion apps/site/gql/requests/getUserId.ts
n1ckoates marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export async function getUserId({
return {
userId: response.users?.items?.[0] ? response.users.items[0].userId : null,
}
}
}
Loading