Files
twenty/packages/twenty-front/src/modules/databases/hooks/useGetDatabaseConnections.ts
T
Félix Malfait 464a480043 Continue ESLINT9 Migration (#13795)
Might already fix #13793
2025-08-10 23:25:58 +02:00

40 lines
1.2 KiB
TypeScript

import { useQuery } from '@apollo/client';
import { GET_MANY_DATABASE_CONNECTIONS } from '@/databases/graphql/queries/findManyDatabaseConnections';
import { getForeignDataWrapperType } from '@/databases/utils/getForeignDataWrapperType';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import {
type GetManyDatabaseConnectionsQuery,
type GetManyDatabaseConnectionsQueryVariables,
} from '~/generated-metadata/graphql';
type UseGetDatabaseConnectionsParams = {
databaseKey: string;
skip?: boolean;
};
export const useGetDatabaseConnections = ({
databaseKey,
skip,
}: UseGetDatabaseConnectionsParams) => {
const apolloMetadataClient = useApolloCoreClient();
const foreignDataWrapperType = getForeignDataWrapperType(databaseKey);
const { data } = useQuery<
GetManyDatabaseConnectionsQuery,
GetManyDatabaseConnectionsQueryVariables
>(GET_MANY_DATABASE_CONNECTIONS, {
client: apolloMetadataClient ?? undefined,
skip: skip || !apolloMetadataClient || !foreignDataWrapperType,
variables: {
input: {
foreignDataWrapperType: foreignDataWrapperType || '',
},
},
});
return {
connections: data?.findManyRemoteServersByType || [],
};
};