twentyhq/twenty · error · Error
Failed to create view
Error message
Failed to create view
What it means
Thrown in usePerformViewAPIPersist when the createView mutation resolves but mutationResult.data.createView is undefined. The GraphQL response did not surface a thrown Apollo error, yet the createView payload is missing, so the optimistic-draft application cannot proceed.
Source
Thrown at packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIPersist.ts:60
mainGroupByFieldMetadataId:
variables.input.mainGroupByFieldMetadataId,
});
}
return createViewMutation({
variables: {
input: {
...variables.input,
id: newViewId,
},
},
});
},
applyResultToDraft: (mutationResult, { addToDraft }) => {
const newView = mutationResult.data?.createView;
if (!isDefined(newView)) {
throw new Error('Failed to create view');
}
const {
__typename,
viewFields: _viewFields,
viewFieldGroups: _viewFieldGroups,
viewFilters: _viewFilters,
viewFilterGroups: _viewFilterGroups,
viewSorts: _viewSorts,
viewGroups,
...flatView
} = newView;
addToDraft({ key: 'views', items: [flatView as FlatView] });
// The server auto-creates viewGroups for Kanban views (mainGroupByFieldMetadataId)
addToDraft({
key: 'viewGroups',View on GitHub (pinned to 1f5dd2bbd2)
Solutions
- Inspect the raw GraphQL response (data + errors) in DevTools for the createView mutation.
- Re-run `npx nx run twenty-front:graphql:generate --configuration=metadata`.
- Verify the user has permission to create views on the target object.
Example fix
// before: if (!isDefined(newView)) { throw new Error('Failed to create view'); }
// after: if (!isDefined(newView)) {
// throw new Error(mutationResult.errors?.[0]?.message ?? 'Failed to create view');
// } Defensive patterns
Strategy: try-catch
Validate before calling
const hasCreateViewPayload = (r: Awaited<ReturnType<typeof createViewMutation>>): boolean => isDefined(r?.data?.createView);
Type guard
const isCreateViewResult = (v: unknown): v is { id: string; name: string } =>
typeof v === 'object' && v !== null && typeof (v as any).id === 'string'; Try / catch
try {
await performViewAPICreate(variables, objectMetadataItemId);
} catch (e) {
showError((e as Error).message); // 'Failed to create view'
} Prevention
- Verify the user has create-view permission on the object before showing the action.
- Keep generated metadata GraphQL in sync after schema changes.
- Have the resolver populate errors so callers can show a meaningful message.
When it happens
Trigger: Server returns 200 with a populated errors array and `{ data: { createView: null } }`. Partial response from a network blip. Selection-set/codegen drift after a schema change.
Common situations: Permission denied creating a view (server returns null + error). Schema change to createView payload not yet codegen'd. Object metadata item id invalid.
Related errors
- Failed to create view filter group
- Failed to create view
- GraphQL errors: ${json.errors.map((e) => e.message).join(';
- No getAuthTokensFromSSOExchangeToken result
- Field ${fieldMetadata.name} is missing, please refresh the p
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/72f0cfff51329730.
Report an issue: GitHub.