cayleygraph/cayley · error
unsupported query type
Error message
unsupported query type
What it means
This error is returned by the GraphQL query parser in Parse when the parsed document does not contain exactly one definition. Cayley's GraphQL-ish schema query layer only accepts a document with a single operation definition, so any other count (zero definitions or multiple definitions) is rejected.
Source
Thrown at query/graphql/graphql.go:426
} else if len(arr) > 1 {
v = arr
}
out[f.Alias] = v
}
return out, nil
}
func Parse(r io.Reader) (*Query, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
doc, err := parser.Parse(parser.ParseParams{Source: string(data)})
if err != nil {
return nil, err
}
if len(doc.Definitions) != 1 {
return nil, fmt.Errorf("unsupported query type")
}
def, ok := doc.Definitions[0].(*ast.OperationDefinition)
if !ok {
return nil, fmt.Errorf("unsupported query type: %T", doc.Definitions[0])
} else if def.Operation != "query" {
return nil, fmt.Errorf("unsupported operation: %s", def.Operation)
}
fields, all, err := setToFields(def.SelectionSet, nil)
if err != nil {
return nil, err
} else if all {
return nil, fmt.Errorf("expand all is not supported at top level")
}
return &Query{fields: fields}, nil
}
func setToFields(set *ast.SelectionSet, labels []quad.Value) (out []field, all bool, _ error) {
if set == nil {View on GitHub (pinned to 81dcd7d73e)
Solutions
- Send exactly one GraphQL operation per request
- Check that the query string is non-empty and not only whitespace/fragments
- Split multiple operations into separate HTTP requests
- Validate the document client-side before sending
Example fix
// before
doc := "query { user } mutation { noop }"
// after
doc := "query { user }" Defensive patterns
Strategy: validation
Validate before calling
function hasSingleDefinition(doc) {
const defs = doc.definitions || [];
return defs.length === 1 && defs[0].kind === 'OperationDefinition';
}
if (!hasSingleDefinition(parsed)) throw new Error('query must contain exactly one operation'); Type guard
const isSingleQuery = (doc) => doc?.definitions?.length === 1 && doc.definitions[0].kind === 'OperationDefinition';
Prevention
- Send one operation per request
- Never post an empty or fragment-only body
- Validate queries with a GraphQL parser client-side first
When it happens
Trigger: Calling Execute/Parse (or issuing an HTTP query) with a GraphQL document whose parsed AST has len(doc.Definitions) != 1 — e.g. an empty query string, a document with only fragments, or a query containing two operations.
Common situations: Sending an empty body or whitespace-only query over the /graphql endpoint; programmatically concatenating two GraphQL operations; sending only a named fragment with no operation.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- unsupported query type: %T
- unsupported operation: %s
- expand all is not supported at top level
- expand all cannot be used with other fields
- Datastore: invalid action
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/95be97d86c5ce83b.
Report an issue: GitHub.