{"record":{"id":"a120411ca515c2c8","repo":"cayleygraph/cayley","slug":"unsupported-query-type-t","errorCode":null,"errorMessage":"unsupported query type: %T","messagePattern":"unsupported query type: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/graphql/graphql.go","lineNumber":430,"sourceCode":"\t}\n\treturn out, nil\n}\n\nfunc Parse(r io.Reader) (*Query, error) {\n\tdata, err := ioutil.ReadAll(r)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdoc, err := parser.Parse(parser.ParseParams{Source: string(data)})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(doc.Definitions) != 1 {\n\t\treturn nil, fmt.Errorf(\"unsupported query type\")\n\t}\n\tdef, ok := doc.Definitions[0].(*ast.OperationDefinition)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unsupported query type: %T\", doc.Definitions[0])\n\t} else if def.Operation != \"query\" {\n\t\treturn nil, fmt.Errorf(\"unsupported operation: %s\", def.Operation)\n\t}\n\tfields, all, err := setToFields(def.SelectionSet, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t} else if all {\n\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) {","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/graphql/graphql.go#L412-L448","documentation":"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.","triggerScenarios":"Sending a GraphQL document whose only definition is `fragment F on X { ... }` (type ast.FragmentDefinition), then calling Parse/Execute or httpQuery with it.","commonSituations":"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.","solutions":["Wrap the fragment in an actual `query { ... }` operation","Spread the fragment inside a query operation","Remove standalone fragment definitions from the request body"],"exampleFix":"// before\nq := \"fragment f on Node { id }\"\n// after\nq := \"query { node { ...f } } fragment f on Node { id }\"","handlingStrategy":"validation","validationCode":"if (doc.definitions.length === 1 && doc.definitions[0].kind !== 'OperationDefinition') {\n  throw new Error('document contains only a fragment; wrap it in a query operation');\n}","typeGuard":"const isOperationDef = (def) => def?.kind === 'OperationDefinition';","tryCatchPattern":null,"preventionTips":["Always pair fragments with an operation","Check the definition kind before sending","Avoid reusing fragment-only documents as queries"],"tags":["graphql","query-parsing","type-mismatch"],"backgroundTag":"schema-validation-failed","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"}