facebook/relay · error
When assigning an array of items, none of the items should…
Error message
When assigning an array of items, none of the items should be null or undefined.
What it means
Thrown when an array assigned to a plural linked field through an updatable proxy contains null or undefined items. Relay cannot link a null entry in the store for a plural linked field, so every element of the assigned array must be a valid record object.
Solutions
- Filter out null/undefined before assigning: `field.set(items.filter(Boolean))`
- Use `items.filter(item => item != null)` to be explicit about both null and undefined
- Fix the server/fragment so list items are non-null (e.g. `[Type!]!]`) if nulls should never appear
Example fix
// before updatable.viewer.friends.set(friends); // after updatable.viewer.friends.set(friends.filter(f => f != null));
Defensive patterns
Strategy: validation
Validate before calling
function assertNoNullItems(items) {
if (items.some(item => item == null)) {
throw new TypeError('Array assigned to plural linked field contains null/undefined items');
}
} Type guard
function hasNoNullItems<T>(items: ReadonlyArray<T | null | undefined>): items is ReadonlyArray<T> {
return items.every((item): item is T => item != null);
} Try / catch
try {
field.set(items);
} catch (e) {
if (e.message.includes('none of the items should be null')) field.set(items.filter(i => i != null));
else throw e;
} Prevention
- Filter nulls from GraphQL list results (lists are nullable by default): items.filter(i => i != null)
- Request non-null list elements in the schema ([Type!]!]) when possible
- Avoid sparse arrays and unfiltered .map results
- Validate arrays at the boundary before passing into updaters
When it happens
Trigger: Calling `pluralField.set(items)` where `items` is an array that includes null or undefined elements, e.g. `set([a, null, c])` or an array built from a sparse or nullable-mapped source.
Common situations: Mapping over server data that contains null list items (GraphQL lists are nullable by default); spreading arrays with holes; filtering logic that leaves undefined entries.
Related errors
- Do not assign null to plural linked fields; assign an empty…
- The __id field must be present on each item passed to the…
- The __id field must be present on the argument. This…
- BabelPluginRelay: Expected a fragment, mutation, query, or…
- BabelPluginRelay: Expected exactly one definition per…
AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02).
Data as JSON: /api/errors/110b980721f2842a.
Report an issue: GitHub.
Appendix: source
Thrown at packages/relay-runtime/mutations/createUpdatableProxy.js:217
}
}
function createSetterForPluralLinkedField(
selection: ReaderLinkedField,
variables: Variables,
updatableProxyRootRecord: RecordProxy,
recordSourceProxy: RecordSourceProxy,
) {
return function set(newValue: ReadonlyArray<{__id: string, ...}>) {
const newVariables = getArgumentValues(selection.args ?? [], variables);
if (newValue == null) {
throw new Error(
'Do not assign null to plural linked fields; assign an empty array instead.',
);
} else {
const recordProxies = newValue.map((item): ?RecordProxy => {
if (item == null) {
throw new Error(
'When assigning an array of items, none of the items should be null or undefined.',
);
}
const {__id} = item;
if (__id == null) {
throw new Error(
'The __id field must be present on each item passed to the setter. This indicates a bug in Relay.',
);
}
const newValueRecord = recordSourceProxy.get(__id);
if (newValueRecord == null) {
throw new Error(
`Did not find item with data id ${__id} in the store.`,
);
}
return newValueRecord;
});
updatableProxyRootRecord.setLinkedRecords(View on GitHub (pinned to 668b1b85e0)