{"record":{"id":"2a2903e4a5bf3cf7","repo":"cayleygraph/cayley","slug":"expand-all-cannot-be-used-with-other-fields","errorCode":null,"errorMessage":"expand all cannot be used with other fields","messagePattern":"expand all cannot be used with other fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/graphql/graphql.go","lineNumber":456,"sourceCode":"\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\")\n\t\t\t\t} else if len(fld.Has) != 0 || len(fld.Fields) != 0 {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"filters inside expand all are not supported\")\n\t\t\t\t}\n\t\t\t\treturn nil, true, nil\n\t\t\t}\n\t\t\tout = append(out, fld)\n\t\tdefault:\n\t\t\treturn nil, false, fmt.Errorf(\"unknown selection type: %T\", s)\n\t\t}\n\t}\n\treturn\n}\n\nfunc stringToVia(s string) (_ quad.IRI, rev bool) {\n\tif len(s) > 0 && s[0] == '~' {\n\t\trev = true\n\t\ts = s[1:]\n\t}","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/graphql/graphql.go#L438-L474","documentation":"When a selection expands to all predicates (the AnyKey wildcard field), it must be the only selection in its set and carry no sub-fields. Combining the wildcard with other sibling fields is ambiguous and rejected.","triggerScenarios":"A selection set containing the expand-all field (`_`) plus at least one other field, e.g. `query { node { _ name } }` — setToFields detects len(set.Selections) != 1 when fld.Via == AnyKey.","commonSituations":"Adding a wildcard 'everything else' alongside named fields; generated queries that append `_` to normal projections; users assuming `_` means 'plus these fields'.","solutions":["Remove sibling fields so the wildcard is the sole selection, or drop the wildcard and list fields explicitly","Split into two queries: one with explicit fields, one using expand-all","Replace `_` with the full list of predicates you want"],"exampleFix":"// before\nq := \"query { node { _ name } }\"\n// after\nq := \"query { node { _ } }\" // or list explicit fields only","handlingStrategy":"validation","validationCode":"function checkWildcardAlone(selections) {\n  const hasWildcard = selections.some(s => s.name?.value === '_');\n  if (hasWildcard && selections.length !== 1) throw new Error('expand all (_) must be the only field in its selection set');\n}","typeGuard":"const isBareWildcard = (sel) => sel.length === 1 && sel[0].name?.value === '_';","tryCatchPattern":null,"preventionTips":["Never mix `_` with named fields","Either list all fields explicitly or expand everything","Add a lint rule for wildcard usage"],"tags":["graphql","expand-all","validation"],"backgroundTag":"invalid-argument","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}