{"record":{"id":"51bd3dab260b8a1e","repo":"cayleygraph/cayley","slug":"expand-all-is-not-supported-at-top-level","errorCode":null,"errorMessage":"expand all is not supported at top level","messagePattern":"expand all is not supported at top level","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/graphql/graphql.go","lineNumber":438,"sourceCode":"\t}\n\tdoc, err := parser.Parse(parser.ParseParams{Source: string(data)})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(doc.Definitions) != 1 {\n\t\treturn nil, fmt.Errorf(\"unsupported query type\")\n\t}\n\tdef, ok := doc.Definitions[0].(*ast.OperationDefinition)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unsupported query type: %T\", doc.Definitions[0])\n\t} else if def.Operation != \"query\" {\n\t\treturn nil, fmt.Errorf(\"unsupported operation: %s\", def.Operation)\n\t}\n\tfields, all, err := setToFields(def.SelectionSet, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t} else if all {\n\t\treturn nil, fmt.Errorf(\"expand all is not supported at top level\")\n\t}\n\treturn &Query{fields: fields}, nil\n}\n\nfunc setToFields(set *ast.SelectionSet, labels []quad.Value) (out []field, all bool, _ error) {\n\tif set == nil {\n\t\treturn\n\t}\n\tfor _, s := range set.Selections {\n\t\tswitch sel := s.(type) {\n\t\tcase *ast.Field:\n\t\t\tfld, err := convField(sel, labels)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, err\n\t\t\t}\n\t\t\tif fld.Via == quad.IRI(AnyKey) {\n\t\t\t\tif len(set.Selections) != 1 {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"expand all cannot be used with other fields\")","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/graphql/graphql.go#L420-L456","documentation":"The expand-all shorthand (the AnyKey wildcard field, typically `_`) selects all predicates, but this library forbids using it at the top level of a query. Top-level selections must be explicit fields; expand all is only allowed nested inside them.","triggerScenarios":"A top-level selection set in the query operation contains the expand-all wildcard field (AnyKey) as its only selection, causing setToFields to return all=true at the root.","commonSituations":"Queries like `query { _ }` intending to dump all predicates of every node; users familiar with `_` expansion on nested nodes applying it at the root; exploratory queries generated by tooling.","solutions":["Name the starting nodes explicitly at the top level and use expand-all (`_`) only in nested selections","Replace the wildcard with the specific predicates you need","Enumerate root nodes with a query (e.g. via has/id) before expanding"],"exampleFix":"// before\nq := \"query { _ }\"\n// after\nq := \"query { node { _ } }\"","handlingStrategy":"validation","validationCode":"const WILDCARD = '_';\nfunction topLevelHasExpandAll(doc) {\n  const sel = doc.definitions[0]?.selectionSet?.selections || [];\n  return sel.some(s => s.name?.value === WILDCARD);\n}","typeGuard":"const isExpandAllSelection = (s) => s?.name?.value === '_';","tryCatchPattern":null,"preventionTips":["Use `_` only in nested selections","Always anchor queries with explicit root fields","Review generated queries for root-level wildcards"],"tags":["graphql","expand-all","validation"],"backgroundTag":"unsupported-operation","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}