cayleygraph/cayley · error

unsupported operation: %s

Error message

unsupported operation: %s

What it means

Returned when the single operation definition exists but its operation type is not "query" — i.e. mutation or subscription was used. Cayley's GraphQL query endpoint is read-only and only supports query operations.

Source

Thrown at query/graphql/graphql.go:432

}

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 {
		return
	}
	for _, s := range set.Selections {
		switch sel := s.(type) {
		case *ast.Field:
			fld, err := convField(sel, labels)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Use `query` operations only; perform writes via Cayley's other write APIs (e.g. the writer/quad endpoints)
  2. Rewrite the operation as a query if read intent was meant
  3. Switch to the gRPC/HTTP write API for data mutations

Example fix

// before
q := "mutation { addPerson }"
// after
q := "query { person }"
Defensive patterns

Strategy: validation

Validate before calling

if (doc.definitions[0]?.operation && doc.definitions[0].operation !== 'query') {
  throw new Error(`unsupported operation: ${doc.definitions[0].operation}; only 'query' is allowed`);
}

Type guard

const isQueryOp = (def) => def?.kind === 'OperationDefinition' && def.operation === 'query';

Prevention

When it happens

Trigger: Submitting `mutation { ... }` or `subscription { ... }` documents to the GraphQL query parser via Execute, Parse, or the HTTP query endpoint.

Common situations: Clients assuming a full GraphQL server (with mutations); auto-generated clients from a schema that declares mutations; testing write operations against Cayley's read-only GraphQL layer.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/243f8d49cf417c12. Report an issue: GitHub.