Skip to content

Commit

Permalink
Merge pull request #203 from yocxo/srizvi/issue202
Browse files Browse the repository at this point in the history
feat: add client list queries #202
  • Loading branch information
srizvi authored Mar 27, 2024
2 parents b19997b + 801fb6e commit fb242fd
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions apps/web/src/basehub/clients-queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type {
ClientItem,
ClientItemGenqlSelection,
FieldsSelection,
} from '.basehub';

import { basehubClient } from './client';

export async function fetchClientsPageMetadata() {
'use server';

const { clients } = await basehubClient.query({
clients: {
meta: {
_sys: {
id: true,
__typename: true,
},
title: true,
description: true,
},
},
});

return {
title: clients.meta.title,
description: clients.meta.description,
};
}

export async function fetchClientsPageIntro() {
'use server';

const { clients } = await basehubClient.query({
clients: {
_sys: {
id: true,
title: true,
slug: true,
__typename: true,
},
pageIntro: {
_sys: {
id: true,
__typename: true,
},
eyebrow: true,
title: true,
description: {
json: {
content: true,
},
},
centered: true,
},
},
});

return {
jsonTitle: clients._sys.title,
jsonSlug: clients._sys.slug,
eyebrow: clients.pageIntro.eyebrow,
title: clients.pageIntro.title,
description: clients.pageIntro.description,
centered: clients.pageIntro.centered,
};
}

export const clientListFragment = {
_sys: {
id: true,
slug: true,
title: true,
createdAt: true,
lastModifiedAt: true,
__typename: true,
},
logo: {
url: true,
alt: true,
},
isPartner: true,
isPublished: true,
} satisfies ClientItemGenqlSelection;

export type ClientListFragment = FieldsSelection<
ClientItem,
typeof clientListFragment
>;

export async function fetchClientList({ skip = 0, first = 10 } = {}) {
'use server';

const { clientList } = await basehubClient.query({
clientList: {
client: {
__args: {
first,
skip,
orderBy: '_sys_title__ASC',
},
items: clientListFragment,
_meta: {
totalCount: true,
},
},
},
});

return {
items: clientList.client.items,
totalCount: clientList.client._meta.totalCount,
};
}

0 comments on commit fb242fd

Please sign in to comment.