import { ApolloClient , NormalizedCacheObject } from '@apollo/client' ; import { GetNamespaceQuery , QueryGetNamespaceArgs , } from '@island.is/web/graphql/schema' ; import { GET_NAMESPACE_QUERY } from '@island.is/web/screens/queries' ; import { NamespaceMessages } from '@island.is/web/hooks/useNamespace' ; export type UiTextGetter = { < Payload extends NamespaceMessages > ( apolloClient , lang , namespace , defaults ? ) : Partial < Payload > ; < Payload extends NamespaceMessages > ( apolloClient , lang , namespace , defaults ) : Payload ; } ; export const getUiTexts = < Payload extends NamespaceMessages > ( apolloClient , lang , namespace , defaults ? ) => apolloClient . query < GetNamespaceQuery , QueryGetNamespaceArgs > ( { query : GET_NAMESPACE_QUERY , variables : { input : { namespace , lang } } , } ) . then ( ( res ) => JSON . parse ( res . data ?. getNamespace ?. fields || '' ) as Payload ) . catch ( ( e ) => defaults || ( { } as Partial < Payload > ) ) ;