TanStackT
TanStack17mo ago
1 reply
foolish-indigo

Attempted to invoke queryFn when set to skipToken. This is likely a configuration error

  loader: ({ context, params }) => {
    const [cookies] = context.cookies
    return context.queryClient.ensureQueryData({
      ...getProjectQueryOpts({
        projectId: cookies.projectId,
      })
    })
  }
});


export const getProjectQueryOpts = (
  variables: Variables,
  init: RequestInit = {},
) => {
  return queryOptions({
    queryKey: [
      "projects",
      variables.projectId
    ],
    queryFn: variables.projectId ? () => getProject(variables, init) : skipToken,
  });
};


Seems like to make this work I have to do this.

export const getProjectQueryOpts = (
  variables: Variables,
  init: RequestInit = {},
) => {
  if (!variables.projectId) {
    return {
      queryKey: ["projects", null],
      queryFn: () => Promise.resolve(null),
    };
  }

  return queryOptions({
    queryKey: [
      "projects",
      variables.projectId
    ],
    queryFn: () => getProject(variables, init),
  });
};

or this

export const getProjectQueryOpts = (
  variables: Variables,
  init: RequestInit = {},
) => {
  return queryOptions({
    queryKey: [
      "projects",
      variables.projectId
    ],
    queryFn: () => variables.projectId ? getProject(variables, init) : null,
  });
};

How come?
Was this page helpful?