UNPKG

@sparklink-pro/apant

Version:

Apollo & Antd tools

22 lines 1.28 kB
import { __rest } from "tslib"; import { useQuery } from '@apollo/client/react'; import { OPERATION_LIST } from '../definitions'; import { useRegistry } from './useRegistry'; import { replaceFragments } from '../helpers/gql'; /** * This hook returns the list of items for a given type. It use `useQuery` to perform a GraphQL query. * It will use the default list operation defined in the registry (OPERATION_LIST) for the type and the default fragment unless a custom fragment is provided. * The query is expected to return a valid payload of the form `{ items: [] }`. */ export function useTypeList(_a) { var { type, fragment } = _a, useQueryOptions = __rest(_a, ["type", "fragment"]); const registry = useRegistry(); const operation = registry.getOperation(type, OPERATION_LIST); const { operations: { list: { getVariables, getResult }, }, } = registry.getType(type); const query = fragment ? replaceFragments(operation, { [registry.getTypeFragmentName(type)]: fragment }) : operation; const { data, loading, refetch } = useQuery(query, Object.assign({ variables: getVariables() }, useQueryOptions)); const items = getResult(data || []); return { loading, items, refetch }; } export default useTypeList; //# sourceMappingURL=useTypeList.js.map