{"record":{"id":"f15dba0bcdaff2cc","repo":"dgraph-io/dgraph","slug":"operation-name-must-by-supplied-when-query-has-mor","errorCode":null,"errorMessage":"Operation name must by supplied when query has more than 1 operation.","messagePattern":"Operation name must by supplied when query has more than 1 operation\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/request.go","lineNumber":64,"sourceCode":"\n\tdoc, gqlErr := parser.ParseQuery(&ast.Source{Input: req.Query})\n\tif gqlErr != nil {\n\t\treturn nil, gqlErr\n\t}\n\n\tlistErr := validator.Validate(s.schema, doc, req.Variables)\n\tif len(listErr) != 0 {\n\t\treturn nil, listErr\n\t}\n\n\tif len(doc.Operations) == 1 && doc.Operations[0].Operation == ast.Subscription &&\n\t\ts.schema.Subscription == nil {\n\t\treturn nil, errors.Errorf(\"Not resolving subscription because schema doesn't have any \" +\n\t\t\t\"fields defined for subscription operation.\")\n\t}\n\n\tif len(doc.Operations) > 1 && req.OperationName == \"\" {\n\t\treturn nil, errors.Errorf(\"Operation name must by supplied when query has more \" +\n\t\t\t\"than 1 operation.\")\n\t}\n\n\top := doc.Operations.ForName(req.OperationName)\n\tif op == nil {\n\t\treturn nil, errors.Errorf(\"Supplied operation name %s isn't present in the request.\",\n\t\t\treq.OperationName)\n\t}\n\n\tvars, gqlErr := validator.VariableValues(s.schema, op, req.Variables)\n\tif gqlErr != nil {\n\t\treturn nil, gqlErr\n\t}\n\n\toperation := &operation{op: op,\n\t\tvars:                    vars,\n\t\tquery:                   req.Query,\n\t\theader:                  req.Header,","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/request.go#L46-L82","documentation":"When the parsed document contains more than one operation, GraphQL requires the client to say which one to execute via the operationName. This error is returned when the request has multiple operations but req.OperationName is empty.","triggerScenarios":"Posting a document like `query A {...} query B {...}` (or query+subscription) in one request without setting Request.OperationName.","commonSituations":"Clients bundling multiple operations in one document; tools like GraphiQL sending the whole editor content; missing operationName in the JSON payload {query, operationName}.","solutions":["Set req.OperationName (or the JSON operationName field) to the name of the operation to execute.","Split the document into one operation per request.","Give the operation a name and pass that name explicitly."],"exampleFix":"// before\n{\"query\": \"query A { me { id } } query B { users { id } }\"}\n// after\n{\"query\": \"query A { me { id } } query B { users { id } }\", \"operationName\": \"A\"}","handlingStrategy":"validation","validationCode":"// client-side: require operationName when the document has >1 operation\nif namedOperationCount(query) > 1 && operationName == \"\" {\n    return errors.New(\"operationName is required for multi-operation documents\")\n}","typeGuard":"func needsOperationName(query, opName string) bool {\n    return namedOperationCount(query) > 1 && opName == \"\"\n}","tryCatchPattern":"op, err := sch.Operation(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"Operation name must by supplied\") {\n        http.Error(w, `please provide operationName`, http.StatusBadRequest)\n        return\n    }\n    return err\n}","preventionTips":["Send one operation per request whenever possible.","Always populate the operationName field in client transports.","Name all operations in stored/committed documents.","Test multi-operation documents in CI."],"tags":["graphql","request","operation-name"],"backgroundTag":"missing-operation-name","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}