cayleygraph/cayley · error
unknown selection type: %T
Error message
unknown selection type: %T
What it means
setToFields switches over the ast.Selection types it understands (fields, fragments) and any other selection type falls into a default case that errors, naming the concrete Go type encountered. This indicates a selection kind the parser does not implement.
Source
Thrown at query/graphql/graphql.go:464
}
for _, s := range set.Selections {
switch sel := s.(type) {
case *ast.Field:
fld, err := convField(sel, labels)
if err != nil {
return nil, false, err
}
if fld.Via == quad.IRI(AnyKey) {
if len(set.Selections) != 1 {
return nil, false, fmt.Errorf("expand all cannot be used with other fields")
} else if len(fld.Has) != 0 || len(fld.Fields) != 0 {
return nil, false, fmt.Errorf("filters inside expand all are not supported")
}
return nil, true, nil
}
out = append(out, fld)
default:
return nil, false, fmt.Errorf("unknown selection type: %T", s)
}
}
return
}
func stringToVia(s string) (_ quad.IRI, rev bool) {
if len(s) > 0 && s[0] == '~' {
rev = true
s = s[1:]
}
if len(s) > 2 && s[0] == '<' && s[len(s)-1] == '>' {
s = s[1 : len(s)-1]
}
return quad.IRI(s), rev
}
func argsToHas(dst []has, args []*ast.Argument, rev bool, labels []quad.Value) (out []has, err error) {
out = dstView on GitHub (pinned to 81dcd7d73e)
Solutions
- Upgrade/downgrade Cayley so its parser and converter versions match
- Check which type appears in the message and avoid that GraphQL construct
- Use standard field and inline-fragment selections only
Defensive patterns
Strategy: type-guard
Validate before calling
// Validate only standard field/fragment selections are used
function usesOnlySupportedSelections(sel) {
return (sel || []).every(s => ['Field','InlineFragment'].includes(s.kind));
} Type guard
const isSupportedSelection = (s) => s && (s.kind === 'Field' || s.kind === 'InlineFragment');
Try / catch
try {
result, err := engine.Parse(ctx, q)
if err != nil {
if strings.HasPrefix(err.Error(), "unknown selection type") {
log.Printf("unsupported GraphQL construct: %v", err)
// degrade or upgrade library
}
return err
}
} Prevention
- Keep the library and its gqlparser dependency versions in sync
- Avoid exotic GraphQL constructs
- Pin dependency versions in go.mod
When it happens
Trigger: A parsed document whose SelectionSet contains a selection type other than *ast.Field or *ast.InlineFragment handling in the switch — e.g. unusual AST shapes produced by certain parser versions or hand-crafted ASTs passed to Parse.
Common situations: Version drift where the gqlparser emits a new selection type; constructing ast.Selection values manually in tests; document features (rare constructs) unsupported by the converter.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- unexpected value type for %v: %T
- unsupported query type: %T
- token not valid
- gae quad: token not valid
- must execute a Step
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/cb6707f57d6996b0.
Report an issue: GitHub.