{"record":{"id":"4f8f357258eadbce","repo":"marmelab/react-admin","slug":"requested-sparse-fields-not-found-ensure-sparse-f","errorCode":null,"errorMessage":"Requested sparse fields not found. Ensure sparse fields are available in the resource's type","messagePattern":"Requested sparse fields not found\\. Ensure sparse fields are available in the resource's type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-data-graphql-simple/src/buildGqlQuery.ts","lineNumber":80,"sourceCode":"                        expandedSparseField.fields[0])\n            );\n\n            if (availableField && expandedSparseField.linkedType) {\n                permitted.linkedSparseFields.push(expandedSparseField);\n                permitted.resourceFields.push(availableField);\n            } else if (availableField)\n                permitted.resourceFields.push(availableField);\n\n            return permitted;\n        },\n        { resourceFields: [], linkedSparseFields: [] }\n    ); // ensure the requested fields are available\n\n    if (\n        permittedSparseFields.resourceFields.length === 0 &&\n        permittedSparseFields.linkedSparseFields.length === 0\n    )\n        throw new Error(\n            \"Requested sparse fields not found. Ensure sparse fields are available in the resource's type\"\n        );\n\n    return permittedSparseFields;\n}\n\nexport default (introspectionResults: IntrospectionResult) =>\n    (\n        resource: IntrospectedResource,\n        raFetchMethod: string,\n        queryType: IntrospectionField,\n        variables: any\n    ) => {\n        const { sortField, sortOrder, ...metaVariables } = variables;\n\n        const apolloArgs = buildApolloArgs(queryType, variables);\n        const args = buildArgs(queryType, variables);\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-data-graphql-simple/src/buildGqlQuery.ts#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\n{ sparseFields: ['titel', 'autr'] } // typos\n// after\n{ sparseFields: ['title', 'author'] }","handlingStrategy":"validation","validationCode":"// Cross-check requested fields against introspection before querying:\nconst typeFields = introspection.types\n  .find(t => t.name === resourceType)?.fields?.map(f => f.name) ?? [];\nconst unknown = sparseFields.filter(f => !typeFields.includes(f));\nif (unknown.length) console.warn('Unknown sparse fields', unknown);","typeGuard":"const fieldsExist = (fields: string[], type: { fields?: { name: string }[] }): boolean =>\n  fields.every(f => type.fields?.some(tf => tf.name === f)) && fields.length > 0;","tryCatchPattern":"try {\n  return await dataProvider.getList(resource, params);\n} catch (e) {\n  if (e.message.includes('Requested sparse fields not found')) {\n    console.error('sparseFields do not match schema for', resource, e);\n    return await dataProvider.getList(resource, { ...params, sparseFields: undefined });\n  }\n  throw e;\n}","preventionTips":["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)."],"tags":["graphql","schema","validation","ra-data-graphql-simple"],"backgroundTag":"field-not-in-schema","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}