{"record":{"id":"add6c4edfc3491b4","repo":"hasura/graphql-engine","slug":"a-selection-set-is-specified-on-field-field-name","errorCode":null,"errorMessage":"a selection set is specified on field '{field_name}' of non-composite type: {type_name}","messagePattern":"a selection set is specified on field '(.+?)' of non-composite type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/lang-graphql/src/validation/error.rs","lineNumber":27,"sourceCode":"    #[error(\"fragment cycle detected through: {0:?}\")]\n    CycleDetected(Vec<ast::Name>),\n    // TODO, this error isn't thrown yet\n    #[error(\"unused fragment: {0}\")]\n    FragmentNotUsed(ast::Name),\n    #[error(\"fragment not defined in the document: {0}\")]\n    UnknownFragment(ast::Name),\n    #[error(\"{} is defined on a non-composite type: {type_name}\", match fragment_name { None => \"inline fragment\".to_owned(), Some(fragment_name) => format!(\"fragment {fragment_name}\")})]\n    FragmentOnNonCompositeType {\n        fragment_name: Option<ast::Name>,\n        type_name: ast::TypeName,\n    },\n    #[error(\"fragment of type {fragment_type} cannot be spread on type {selection_type}\")]\n    FragmentCannotBeSpread {\n        selection_type: ast::TypeName,\n        fragment_type: ast::TypeName,\n    },\n    // TODO, this error isn't thrown yet\n    #[error(\n        \"a selection set is specified on field '{field_name}' of non-composite type: {type_name}\"\n    )]\n    SelectionOnNonCompositeType {\n        field_name: ast::Name,\n        type_name: ast::TypeName,\n    },\n    #[error(\"no such field on type {type_name}: {field_name}\")]\n    NoFieldOnType {\n        type_name: ast::TypeName,\n        field_name: ast::Name,\n    },\n    #[error(\"no such type defined in the document: {0}\")]\n    UnknownType(ast::TypeName),\n    #[error(\"an internal error occurred during validation: type lookup failed for {type_name}\")]\n    InternalTypeNotFound { type_name: ast::TypeName },\n    #[error(\n        \"an internal error occurred during validation: field {field_name} lookup failed for sub type '{sub_type_name}' of type '{type_name}'\"\n    )]","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/lang-graphql/src/validation/error.rs#L9-L45","documentation":"Thrown when a field whose GraphQL type is non-composite (scalar/enum) is selected with a sub-selection set, e.g. `name { first }` where `name: String`. Field selection sets are only legal on composite types (objects/interfaces/unions). The error carries the field name and the offending type name so you can locate the selection.","triggerScenarios":"Adding `{ ... }` braces after a scalar or enum field; treating a JSON-ish scalar as an object; querying a field whose type was changed from object to scalar/enum in the schema while keeping the old nested selection.","commonSituations":"Schema evolution flattened or scalarized a field but clients kept nested selections; custom scalars (e.g. JSON) mistakenly queried with subfields instead of being treated as opaque leaves; hand-writing queries without a schema-aware editor.","solutions":["Remove the sub-selection set from the non-composite field and select it as a leaf (`name` instead of `name { ... }`)","If the field should have subfields, fix the schema so the field returns an object type","Update/regenerate client queries after schema type changes"],"exampleFix":"// before\n{ user { name { first } } }\n// after\n{ user { name } }","handlingStrategy":"validation","validationCode":"let ft = schema.field_type(parent_type, field_name); if !ft.is_composite() { assert!(!selection.has_subselection(field_name), \"scalar field cannot have a selection set\"); }","typeGuard":"fn needs_selection_set(t: &Type) -> bool { t.is_composite() }","tryCatchPattern":"match validate(doc) { Err(Error::SelectionOnNonCompositeType { field_name, type_name }) => strip_subselection(field_name), r => r }","preventionTips":["Select scalars/enums as leaves with no braces","Use a GraphQL LSP/editor that marks illegal sub-selections","Treat custom JSON scalars as opaque leaves"],"tags":["graphql","selection-set","scalar-field","validation"],"backgroundTag":"graphql-selection-on-non-composite-type","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}