Skip to content

Commit

Permalink
feat: rename lazy to fetchOnMount
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Oct 5, 2020
1 parent 46c22af commit 68b937e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/villus/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface QueryCompositeOptions<TVars> {
query: MaybeReactive<Operation['query']>;
variables?: MaybeReactive<TVars>;
cachePolicy?: CachePolicy;
lazy?: boolean;
fetchOnMount?: boolean;
}

interface QueryExecutionOpts {
Expand Down Expand Up @@ -125,8 +125,7 @@ function useQuery<TData = any, TVars = QueryVariables>(
): ThenableQueryComposable<TData> {
const normalizedOpts = normalizeOptions(opts, variables);
const api = _useQuery<TData, TVars>(normalizedOpts);
// Fetch on mounted if lazy is disabled.
if (!normalizedOpts.lazy) {
if (normalizedOpts.fetchOnMount) {
onMounted(() => {
api.execute();
});
Expand All @@ -146,11 +145,19 @@ function normalizeOptions<TVars>(
opts: QueryCompositeOptions<TVars> | QueryCompositeOptions<TVars>['query'],
variables?: QueryCompositeOptions<TVars>['variables']
): QueryCompositeOptions<TVars> {
const defaultOpts = {
fetchOnMount: true,
};

if (typeof opts !== 'string' && 'query' in opts) {
return opts;
return {
...defaultOpts,
...opts,
};
}

return {
...defaultOpts,
query: opts,
variables,
};
Expand Down

0 comments on commit 68b937e

Please sign in to comment.