2025-04-16 16:55:38 -07:00
|
|
|
import { useGetEntitiesQuery } from '@graphql/entity.generated';
|
|
|
|
|
import { Entity } from '@types';
|
2025-01-29 20:42:01 -05:00
|
|
|
|
2025-07-18 02:21:02 +05:30
|
|
|
export function useGetEntities(urns: string[]): {
|
|
|
|
|
entities: Entity[];
|
|
|
|
|
loading: boolean;
|
|
|
|
|
} {
|
|
|
|
|
const verifiedUrns = urns.filter((urn) => typeof urn === 'string' && urn.startsWith('urn:li:'));
|
2025-01-29 20:42:01 -05:00
|
|
|
|
2025-07-18 15:03:40 -04:00
|
|
|
const { data, loading } = useGetEntitiesQuery({
|
|
|
|
|
variables: { urns: verifiedUrns },
|
|
|
|
|
skip: !verifiedUrns.length,
|
|
|
|
|
fetchPolicy: 'cache-first',
|
|
|
|
|
});
|
2025-07-18 02:21:02 +05:30
|
|
|
const entities: Entity[] = Array.isArray(data?.entities) ? (data?.entities.filter(Boolean) as Entity[]) : [];
|
|
|
|
|
return { entities, loading };
|
2025-01-29 20:42:01 -05:00
|
|
|
}
|