Closes https://github.com/twentyhq/twenty/issues/4555 <img width="593" alt="Capture d’écran 2024-04-05 à 11 54 28" src="https://github.com/twentyhq/twenty/assets/22936103/e6021417-bc78-460b-adf6-834330bbd894"> Connect the existing for with the backend so we can now create database connections. --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
40 lines
1.2 KiB
TypeScript
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 { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
|
|
import {
|
|
GetManyDatabaseConnectionsQuery,
|
|
GetManyDatabaseConnectionsQueryVariables,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
type UseGetDatabaseConnectionsParams = {
|
|
databaseKey: string;
|
|
skip?: boolean;
|
|
};
|
|
|
|
export const useGetDatabaseConnections = ({
|
|
databaseKey,
|
|
skip,
|
|
}: UseGetDatabaseConnectionsParams) => {
|
|
const apolloMetadataClient = useApolloMetadataClient();
|
|
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 || [],
|
|
};
|
|
};
|