marmelab/react-admin · error · Error
Requested sparse fields not found. Ensure sparse fields are
Error message
Requested sparse fields not found. Ensure sparse fields are available in the resource's type
What it means
After filtering the requested sparseFields against the resource's GraphQL introspected type, neither direct fields nor linked sparse fields matched. This means none of the requested fields exist on the resource type, so building a selection set is impossible.
Source
Thrown at packages/ra-data-graphql-simple/src/buildGqlQuery.ts:80
expandedSparseField.fields[0])
);
if (availableField && expandedSparseField.linkedType) {
permitted.linkedSparseFields.push(expandedSparseField);
permitted.resourceFields.push(availableField);
} else if (availableField)
permitted.resourceFields.push(availableField);
return permitted;
},
{ resourceFields: [], linkedSparseFields: [] }
); // ensure the requested fields are available
if (
permittedSparseFields.resourceFields.length === 0 &&
permittedSparseFields.linkedSparseFields.length === 0
)
throw new Error(
"Requested sparse fields not found. Ensure sparse fields are available in the resource's type"
);
return permittedSparseFields;
}
export default (introspectionResults: IntrospectionResult) =>
(
resource: IntrospectedResource,
raFetchMethod: string,
queryType: IntrospectionField,
variables: any
) => {
const { sortField, sortOrder, ...metaVariables } = variables;
const apolloArgs = buildApolloArgs(queryType, variables);
const args = buildArgs(queryType, variables);
View on GitHub (pinned to 051f511bb0)
Solutions
- Run the introspection / inspect the GraphQL schema and use exact field names for the resource type.
- Fix typos and casing in sparseFields entries (GraphQL fields are camelCase-sensitive).
- Verify the sparseFields belong to the resource you are querying, not another type.
- Use nested 'linked' field syntax only for actual relations exposed in the schema.
Example fix
// before
{ sparseFields: ['titel', 'autr'] } // typos
// after
{ sparseFields: ['title', 'author'] } Defensive patterns
Strategy: validation
Validate before calling
// Cross-check requested fields against introspection before querying:
const typeFields = introspection.types
.find(t => t.name === resourceType)?.fields?.map(f => f.name) ?? [];
const unknown = sparseFields.filter(f => !typeFields.includes(f));
if (unknown.length) console.warn('Unknown sparse fields', unknown); Type guard
const fieldsExist = (fields: string[], type: { fields?: { name: string }[] }): boolean =>
fields.every(f => type.fields?.some(tf => tf.name === f)) && fields.length > 0; Try / catch
try {
return await dataProvider.getList(resource, params);
} catch (e) {
if (e.message.includes('Requested sparse fields not found')) {
console.error('sparseFields do not match schema for', resource, e);
return await dataProvider.getList(resource, { ...params, sparseFields: undefined });
}
throw e;
} Prevention
- Generate sparseFields from schema/introspection rather than hardcoding.
- Add a startup check comparing configured fields with the introspected schema.
- Keep frontend field configs in sync when the backend schema changes (CI schema diff).
When it happens
Trigger: Passing sparseFields whose names do not match any field of the resource's GraphQL type (typos, wrong casing, fields from a different resource), such that both permittedSparseFields.resourceFields and linkedSparseFields end up empty.
Common situations: Renamed backend schema fields without updating frontend config; copying sparseFields between resources; GraphQL type introspection returning a different type than expected (e.g. wrong resource name).
Related errors
- Empty sparse fields. Specify at least one field or remove th
- 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/4f8f357258eadbce.
Report an issue: GitHub.