import { useQuery } from "@apollo/client" ; import { DocumentNode } from "graphql" ; export const useGetQueryDataByFieldName = < FieldType > ( query , fieldName ) => { const result = useQuery < Record < string , FieldType > > ( query , { fetchPolicy : 'cache-only' , } ) ; const requiredDataResult = { ... result , data : result ?. data ?. [ fieldName ] , } ; type RequiredDataResult = typeof requiredDataResult & { data : FieldType ; } ; return requiredDataResult as RequiredDataResult ; } ;