{"record":{"id":"8e85a9ebd9cba381","repo":"dgraph-io/dgraph","slug":"no-query-string-supplied-in-request","errorCode":null,"errorMessage":"no query string supplied in request","messagePattern":"no query string supplied in request","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/request.go","lineNumber":44,"sourceCode":"}\n\n// RequestExtensions represents extensions recieved in requests\ntype RequestExtensions struct {\n\tPersistedQuery PersistedQuery\n}\n\n// PersistedQuery represents the query struct received from clients like Apollo\ntype PersistedQuery struct {\n\tSha256Hash string\n}\n\n// Operation finds the operation in req, if it is a valid request for GraphQL\n// schema s. If the request is GraphQL valid, it must contain a single valid\n// Operation.  If either the request is malformed or doesn't contain a valid\n// operation, all GraphQL errors encountered are returned.\nfunc (s *schema) Operation(req *Request) (Operation, error) {\n\tif req == nil || req.Query == \"\" {\n\t\treturn nil, errors.New(\"no query string supplied in request\")\n\t}\n\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","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/request.go#L26-L62","documentation":"schema.Operation validates an incoming GraphQL request and must find a single valid operation. If the Request is nil or its Query string is empty, there is nothing to parse, so this error is returned before any parsing happens.","triggerScenarios":"Calling s.Operation(req) with req == nil, or a *graphql.Request whose Query field was never set / set to \"\" — e.g. posting an empty body or a request that only carried variables.","commonSituations":"HTTP client POSTs an empty body or JSON without a \"query\" key; a middleware strips the body; a transport bug sends GET without ?query=; tests constructing Request{} without Query.","solutions":["Set req.Query to the GraphQL document string before calling Operation.","Check the HTTP client is actually sending the query (inspect request body / query param).","Return a 400 to the client when the query string is missing instead of retrying."],"exampleFix":"// before\nreq := &graphQLapi.Request{Variables: vars}\n// after\nreq := &graphQLapi.Request{Query: \"{ queryUser { name } }\", Variables: vars}","handlingStrategy":"validation","validationCode":"func validateGraphQLRequest(req *Request) error {\n    if req == nil || strings.TrimSpace(req.Query) == \"\" {\n        return errors.New(\"request must include a non-empty query\")\n    }\n    return nil\n}","typeGuard":"func hasQuery(req *Request) bool {\n    return req != nil && req.Query != \"\"\n}","tryCatchPattern":"op, err := schema.Operation(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"no query string supplied\") {\n        http.Error(w, `{\"errors\":[{\"message\":\"query is required\"}]}`, http.StatusBadRequest)\n        return\n    }\n    http.Error(w, err.Error(), http.StatusInternalServerError)\n}","preventionTips":["Always construct Request with Query set before calling Operation.","On the HTTP layer, reject requests with empty bodies early with a 400.","For GET requests, validate the ?query= param exists.","Add a unit test for empty-body requests."],"tags":["graphql","request","validation"],"backgroundTag":"missing-graphql-query","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}