refinedev/refine · error · Error
Invalid action type
Error message
Invalid action type
What it means
Refine's TanStack Query key builders (p(resource).action(actionType)) only accept 'many' (DataIds), 'list' and 'infinite' (Params). Any other string passed to action() hits this guard.
Source
Thrown at packages/core/src/definitions/helpers/keys/index.ts:125
action(actionType: ParametrizedDataActions): ParamsKeyBuilder;
action(actionType: IdRequiredDataActions): DataIdRequiringKeyBuilder;
action(actionType: IdsRequiredDataActions): DataIdsRequiringKeyBuilder;
action(
actionType:
| ParametrizedDataActions
| IdRequiredDataActions
| IdsRequiredDataActions,
): ParamsKeyBuilder | DataIdRequiringKeyBuilder | DataIdsRequiringKeyBuilder {
if (actionType === "one") {
return new DataIdRequiringKeyBuilder([...this.segments, actionType]);
}
if (actionType === "many") {
return new DataIdsRequiringKeyBuilder([...this.segments, actionType]);
}
if (["list", "infinite"].includes(actionType)) {
return new ParamsKeyBuilder([...this.segments, actionType]);
}
throw new Error("Invalid action type");
}
}
class DataKeyBuilder extends BaseKeyBuilder {
resource(resourceName?: string) {
return new DataResourceKeyBuilder([...this.segments, resourceName]);
}
mutation(mutationName: DataMutationActions) {
return new ParamsKeyBuilder([
...(mutationName === "custom" ? this.segments : [this.segments[0]]),
mutationName,
]);
}
}
class AuthKeyBuilder extends BaseKeyBuilder {
action(actionType: AuthActionType) {View on GitHub (pinned to 779d52a20e)
Solutions
- Use 'many', 'list', or 'infinite' as the actionType
- For single-record queries use the appropriate detail key builder instead of action()
- Type the actionType as the builder's expected union to catch mistakes at compile time
Example fix
// before
queryClient.invalidateQueries(keyBuilder.data('posts').action('detail'));
// after
queryClient.invalidateQueries(keyBuilder.data('posts').action('list')); Defensive patterns
Strategy: type-guard
Validate before calling
const VALID_ACTIONS = ['many','list','infinite'] as const;
if (!VALID_ACTIONS.includes(actionType)) throw new Error('invalid action'); Type guard
const isValidAction = (a: string): a is 'many' | 'list' | 'infinite' => ['many','list','infinite'].includes(a as any);
Prevention
- Type key-builder inputs with the literal union
- Use exported key builder APIs rather than hand-built strings
When it happens
Trigger: Calling keys().data(resource).action('one') or action('edit') — i.e. an action type outside ['many','list','infinite'] — typically when composing custom query keys or invalidating queries.
Common situations: Writing custom invalidation code that guesses at action names; refactor from older key formats; passing a resource action like 'create' instead of a query action.
Related errors
- GraphQL need to operation, fields and variables values in me
- GraphQL needs operation, fields and variables values in meta
- Value array must contain exactly two elements for "between"
- Invalid provider: ${providerId}
- useGetLocale cannot be called without i18n provider being de
AI-assisted analysis of refinedev/refine@779d52a20e (2026-08-27).
Data as JSON: /api/errors/88337533a5e87d2e.
Report an issue: GitHub.