Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion npm-packages/convex/src/browser/query_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export type QueryOptions<Query extends FunctionReference<"query">> = {
// This helper helps more once we have more inference happening.
export function convexQueryOptions<Query extends FunctionReference<"query">>(
options: QueryOptions<Query>,
) {
): QueryOptions<Query> {
return options;
}
38 changes: 23 additions & 15 deletions npm-packages/convex/src/react/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,20 +808,26 @@ export type OptionalRestArgsOrSkip<FuncRef extends FunctionReference<any>> =
*
* @public
*/
export type UseQueryOptions<Query extends FunctionReference<"query">> =
QueryOptions<Query> & {
/**
* Whether to throw an error if the query fails.
* If false, the error will be returned in the `error` field.
* @defaultValue false
*/
throwOnError?: boolean;
/**
* An initial value to use before the query result is available.
* @defaultValue undefined
*/
initialValue?: Query["_returnType"];
};
export type UseQueryOptions<Query extends FunctionReference<"query">> = (
| (QueryOptions<Query> & { skip?: false })
| {
query: Query;
args?: unknown;
skip: true;
}
) & {
/**
* Whether to throw an error if the query fails.
* If false, the error will be returned in the `error` field.
* @defaultValue false
*/
throwOnError?: boolean;
/**
* An initial value to use before the query result is available.
* @defaultValue undefined
*/
initialValue?: Query["_returnType"];
};

/**
* Options for the object-based {@link useQuery} overload with a preloaded query.
Expand Down Expand Up @@ -941,7 +947,9 @@ export function useQuery<Query extends FunctionReference<"query">>(
typeof query === "string"
? (makeFunctionReference<"query", any, any>(query) as Query)
: query;
argsObject = queryOrOptions.args ?? ({} as Record<string, Value>);
if (!queryOrOptions.skip && queryOrOptions.args) {
argsObject = queryOrOptions.args;
}
throwOnError = queryOrOptions.throwOnError ?? false;
initialValue = queryOrOptions.initialValue;
}
Expand Down
8 changes: 8 additions & 0 deletions npm-packages/convex/src/react/use_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ describe("useQuery types", () => {
args: { _arg: "asdf" },
});

const userId = undefined as string | undefined;

useQuery({
query: api.module.args,
args: { _arg: userId },
skip: !userId,
});

useQuery({
query: api.module.args,
args: { _arg: "asdf" },
Expand Down
Loading