feat: fetch database connections (#4813)

Closes #4757

---------

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thaïs
2024-04-04 17:27:36 +02:00
committed by GitHub
parent f8edb6652e
commit 1f98bc899d
10 changed files with 113 additions and 51 deletions

View File

@ -0,0 +1,14 @@
import { gql } from '@apollo/client';
export const GET_MANY_DATABASE_CONNECTIONS = gql`
query GetManyDatabaseConnections($input: RemoteServerTypeInput!) {
findManyRemoteServersByType(input: $input) {
id
createdAt
foreignDataWrapperId
foreignDataWrapperOptions
foreignDataWrapperType
updatedAt
}
}
`;

View File

@ -0,0 +1,37 @@
import { useQuery } from '@apollo/client';
import { GET_MANY_DATABASE_CONNECTIONS } from '@/databases/graphql/queries/findManyDatabaseConnections';
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 { data } = useQuery<
GetManyDatabaseConnectionsQuery,
GetManyDatabaseConnectionsQueryVariables
>(GET_MANY_DATABASE_CONNECTIONS, {
client: apolloMetadataClient ?? undefined,
skip: skip || !apolloMetadataClient || databaseKey !== 'postgresql',
variables: {
input: {
foreignDataWrapperType: 'postgres_fdw',
},
},
});
return {
connections: data?.findManyRemoteServersByType || [],
};
};