feat: fetch database connections (#4813)
Closes #4757 --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -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 || [],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user