marmelab/react-admin · error · Error
Empty sparse fields. Specify at least one field or remove th
Error message
Empty sparse fields. Specify at least one field or remove the 'sparseFields' param
What it means
In ra-data-graphql-simple, the sparseFields option restricts a GraphQL query to a subset of fields. processSparseFields validates the supplied list up front and throws if it is empty or falsy, because an empty selection set would produce an invalid or meaningless query.
Source
Thrown at packages/ra-data-graphql-simple/src/buildGqlQuery.ts:40
} from 'graphql';
import * as gqlTypes from 'graphql-ast-types-browser';
import getFinalType from './getFinalType';
import { getGqlType } from './getGqlType';
type SparseField = string | { [k: string]: SparseField[] };
type ExpandedSparseField = { linkedType?: string; fields: SparseField[] };
type ProcessedFields = {
resourceFields: IntrospectionField[];
linkedSparseFields: ExpandedSparseField[];
};
function processSparseFields(
resourceFields: readonly IntrospectionField[],
sparseFields: SparseField[]
): ProcessedFields & { resourceFields: readonly IntrospectionField[] } {
if (!sparseFields || sparseFields.length === 0)
throw new Error(
"Empty sparse fields. Specify at least one field or remove the 'sparseFields' param"
);
const permittedSparseFields: ProcessedFields = sparseFields.reduce(
(permitted: ProcessedFields, sparseField: SparseField) => {
let expandedSparseField: ExpandedSparseField;
if (typeof sparseField == 'string')
expandedSparseField = { fields: [sparseField] };
else {
const [linkedType, linkedSparseFields] =
Object.entries(sparseField)[0];
expandedSparseField = {
linkedType,
fields: linkedSparseFields,
};
}
const availableField = resourceFields.find(View on GitHub (pinned to 051f511bb0)
Solutions
- Provide at least one field in the sparseFields array.
- Omit the sparseFields param entirely when you want all fields.
- Guard before calling: only pass sparseFields when the array has entries.
Example fix
// before
buildQuery('GET_LIST', 'Post', { sparseFields: [] });
// after
buildQuery('GET_LIST', 'Post', { sparseFields: ['id', 'title'] }); // or omit sparseFields Defensive patterns
Strategy: validation
Validate before calling
const options = sparseFields?.length ? { sparseFields } : {};
buildQuery(fetchType, resource, { ...params, ...options }); Type guard
const hasSparseFields = (f: unknown): f is string[] => Array.isArray(f) && f.length > 0;
Try / catch
try {
return await dataProvider.getList(resource, params);
} catch (e) {
if (e.message.includes('Empty sparse fields')) {
return await dataProvider.getList(resource, { ...params, sparseFields: undefined });
}
throw e;
} Prevention
- Only set sparseFields in config when the array is non-empty.
- Centralize provider options construction so empty arrays are stripped.
- Validate config files at startup.
When it happens
Trigger: Passing sparseFields: [] or sparseFields: undefined/null to a buildQuery factory (or data provider options) while explicitly opting into sparse field selection.
Common situations: Building the fields array conditionally from user config or feature flags and ending up with an empty array; JSON config files with an empty 'sparseFields' list.
Related errors
- Requested sparse fields not found. Ensure sparse fields are
- Unknown resource ${resourceName}. Make sure it has been decl
- No query or mutation matching fetch type ${raFetchType} coul
- useCreate mutation requires a resource
- useCreate mutation requires a non-empty data object
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/c77c6ca48eac690b.
Report an issue: GitHub.