Refactor people query into separate file.

This commit is contained in:
Anders Borch
2023-04-24 11:10:56 +02:00
parent a5bfeef2d6
commit 47bdabd5aa
3 changed files with 34 additions and 26 deletions

View File

@ -0,0 +1 @@
export * from './select';

View File

@ -0,0 +1,30 @@
import { QueryResult, gql, useQuery } from '@apollo/client';
import { GraphqlPerson } from '../../interfaces/person.interface';
export type OrderBy = Record<string, 'asc' | 'desc'>;
export const GET_PEOPLE = gql`
query GetPeople($orderBy: [people_order_by!]) {
people(order_by: $orderBy) {
id
phone
email
city
firstname
lastname
created_at
company {
company_name
company_domain
}
}
}
`;
export function usePeopleQuery(
orderBy: OrderBy[],
): QueryResult<{ people: GraphqlPerson[] }> {
return useQuery<{ people: GraphqlPerson[] }>(GET_PEOPLE, {
variables: { orderBy },
});
}