TripleSpeederT
Convex Community2y ago
3 replies
TripleSpeeder

typed useQuery mock

I'm trying to make a quick mock for useQuery. It's basically working, but I would like to have the query typed.
This is the current implementation:
export const useQuery = fn((query, ...args) => {
  if (args[0] === "skip") {
    return undefined;
  }
  const queryName = getFunctionName(query);
  switch (queryName) {
    case "manufacturer/queries:getManufacturerQuery":
      return manufacturer;
    default:
      throw new Error(
        `Unexpected query call ${queryName}! Please add a mock :)`,
      );
  ...

What are the correct types for query and ...args? I would like the return of getFunctionName to be typed based on my schema/api. Is this possible?
Was this page helpful?