T
TanStack12mo ago
eastern-cyan

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,
})
})
}
});
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,
});
};
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),
});
};
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,
});
};
export const getProjectQueryOpts = (
variables: Variables,
init: RequestInit = {},
) => {
return queryOptions({
queryKey: [
"projects",
variables.projectId
],
queryFn: () => variables.projectId ? getProject(variables, init) : null,
});
};
How come?
1 Reply
quickest-silver
quickest-silver12mo ago
enabled only works on hooks, and skipToken is "just" a type-safe implementation of enabled. Imperative methods can just not be called if you don' thave the available data, so:
loader: ({ context, params }) => {
const [cookies] = context.cookies
+ if (!cookies.projectId) return null
return context.queryClient.ensureQueryData({
...getProjectQueryOpts({
projectId: cookies.projectId,
})
})
}
});
loader: ({ context, params }) => {
const [cookies] = context.cookies
+ if (!cookies.projectId) return null
return context.queryClient.ensureQueryData({
...getProjectQueryOpts({
projectId: cookies.projectId,
})
})
}
});

Did you find this page helpful?