cayleygraph/cayley · error

unsupported query type: %T

Error message

unsupported query type: %T

What it means

Returned when the single parsed definition is not an *ast.OperationDefinition — e.g. the document's sole definition is a fragment definition. The parser only handles operation definitions and includes the concrete Go type in the message for debugging.

Source

Thrown at query/graphql/graphql.go:430

	}
	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 {
		return
	}
	for _, s := range set.Selections {
		switch sel := s.(type) {

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Wrap the fragment in an actual `query { ... }` operation
  2. Spread the fragment inside a query operation
  3. Remove standalone fragment definitions from the request body

Example fix

// before
q := "fragment f on Node { id }"
// after
q := "query { node { ...f } } fragment f on Node { id }"
Defensive patterns

Strategy: validation

Validate before calling

if (doc.definitions.length === 1 && doc.definitions[0].kind !== 'OperationDefinition') {
  throw new Error('document contains only a fragment; wrap it in a query operation');
}

Type guard

const isOperationDef = (def) => def?.kind === 'OperationDefinition';

Prevention

When it happens

Trigger: Sending a GraphQL document whose only definition is `fragment F on X { ... }` (type ast.FragmentDefinition), then calling Parse/Execute or httpQuery with it.

Common situations: Clients that reuse fragment-only documents; tooling that builds documents from fragments and forgets to attach an operation; copy-pasted snippets containing only a fragment.

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


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