@apollo/client#LazyQueryHookOptions TypeScript Examples
The following examples show how to use
@apollo/client#LazyQueryHookOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useRefreshToken.ts From lexicon with MIT License | 6 votes |
export function useRefreshToken(
options?: LazyQueryHookOptions<RefreshToken>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
) {
const [getRefreshToken, { data, error }] = useLazyQuery<RefreshToken>(
REFRESH_TOKEN,
{
...options,
},
errorAlert,
);
return { getRefreshToken, data, error };
}
Example #2
Source File: useActivity.ts From lexicon with MIT License | 6 votes |
export function useLazyActivity(
options?: LazyQueryHookOptions<UserActivityType, UserActivityVariables>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
) {
const [getActivity, { data, error }] = useLazyQuery<
UserActivityType,
UserActivityVariables
>(
USER_ACTIVITY,
{
...options,
},
errorAlert,
);
return { getActivity, data, error };
}
Example #3
Source File: useLookupUrls.ts From lexicon with MIT License | 6 votes |
export function useLookupUrls(
options?: LazyQueryHookOptions<LookupUrls, LookupUrlsVariables>,
) {
const [getImageUrls] = useLazyQuery<LookupUrls, LookupUrlsVariables>(
LOOKUP_URLS,
{ ...options },
);
return { getImageUrls };
}
Example #4
Source File: useSearchPost.ts From lexicon with MIT License | 6 votes |
export function useSearchPost(
options?: LazyQueryHookOptions<SearchPostType, SearchPostVariables>,
) {
const [getPosts, { error, refetch, fetchMore }] = useLazyQuery<
SearchPostType,
SearchPostVariables
>(SEARCH, {
...options,
});
return { getPosts, error, refetch, fetchMore };
}
Example #5
Source File: useTopicList.ts From lexicon with MIT License | 6 votes |
export function useLazyTopicList(
options?: LazyQueryHookOptions<TopicListType, TopicListVariables>,
) {
const [getTopicList, { loading, error, refetch, fetchMore }] = useLazyQuery<
TopicListType,
TopicListVariables
>(TOPICS, { ...options });
return { getTopicList, loading, error, refetch, fetchMore };
}
Example #6
Source File: useProfile.ts From lexicon with MIT License | 6 votes |
export function useLazyProfile(
options?: LazyQueryHookOptions<ProfileType, ProfileVariables>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
) {
const [getProfile, { data }] = useLazyQuery<ProfileType, ProfileVariables>(
PROFILE,
{
...options,
},
errorAlert,
);
return { getProfile, data };
}
Example #7
Source File: useAbout.ts From lexicon with MIT License | 6 votes |
export function useAbout(
options?: LazyQueryHookOptions<AboutType>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
) {
const [getAbout, { error }] = useLazyQuery<AboutType>(
ABOUT,
{
...options,
},
errorAlert,
);
return { getAbout, error };
}
Example #8
Source File: useSingleBadge.ts From lexicon with MIT License | 6 votes |
export function useSingleBadge(
options?: LazyQueryHookOptions<SingleBadge, SingleBadgeVariables>,
) {
const [singleBadge] = useLazyQuery<SingleBadge, SingleBadgeVariables>(
SINGLE_BADGE,
{
...options,
},
);
return { singleBadge };
}
Example #9
Source File: useTags.ts From lexicon with MIT License | 6 votes |
export function useTags(
options?: LazyQueryHookOptions<TagsType, TagsVariables>,
) {
const [getTags, { data, loading, error, refetch }] = useLazyQuery<
TagsType,
TagsVariables
>(SEARCH_TAGS, {
...options,
});
return { getTags, data, loading, error, refetch };
}
Example #10
Source File: useLazyQuery.ts From lexicon with MIT License | 6 votes |
export function useLazyQuery<TData, TVariables = OperationVariables>(
query: DocumentNode,
options?: LazyQueryHookOptions<TData, TVariables>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
): QueryTuple<TData, TVariables> {
const onErrorDefault = (error: ApolloError) => {
errorHandlerAlert(error);
};
const { fetchPolicy = 'cache-and-network', ...others } = options ?? {};
const {
onError = errorAlert === 'SHOW_ALERT' ? onErrorDefault : undefined,
nextFetchPolicy = fetchPolicy === 'cache-and-network'
? 'cache-first'
: undefined,
notifyOnNetworkStatusChange = fetchPolicy === 'network-only',
...otherOptions
} = others;
let [queryFunction, queryResult] = useLazyQueryBase<TData, TVariables>(
query,
{
fetchPolicy,
nextFetchPolicy,
notifyOnNetworkStatusChange,
onError,
...otherOptions,
},
);
return [queryFunction, queryResult];
}
Example #11
Source File: useBlockPollingSubscription.ts From mStable-apps with GNU Lesser General Public License v3.0 | 5 votes |
useBlockPollingSubscription = <TData, TVariables>(
lazyQuery: (query: unknown, options?: LazyQueryHookOptions<TData, TVariables>) => QueryTuple<TData, TVariables>,
baseOptions?: LazyQueryHookOptions<TData, TVariables>,
skip?: boolean,
): QueryResult<TData, TVariables> => {
const errorRef = useRef<unknown>()
const network = useNetwork()
const blockNumber = useBlockNow()
const hasBlock = !!blockNumber
// We're using a long-polling query because subscriptions don't seem to be
// re-run when derived or nested fields change.
// See https://github.com/graphprotocol/graph-node/issues/1398
const [run, query] = lazyQuery({
...baseOptions,
errorPolicy: 'all',
onError: (error: unknown) => {
errorRef.current = error
},
})
// Long poll (15s interval) if the block number isn't available.
useEffect(() => {
let interval: NodeJS.Timeout
if (!skip && !hasBlock && !errorRef.current) {
run()
interval = setInterval(() => {
run()
}, network.blockTime)
}
return () => {
clearInterval(interval)
}
}, [skip, hasBlock, run, network])
// Run the query on every block when the block number is available.
useEffect(() => {
if (!skip && blockNumber) {
run()
}
}, [skip, blockNumber, run, network])
return query as never
}