{"record":{"id":"b06d7a30166d5914","repo":"dgraph-io/dgraph","slug":"not-resolving-subscription-because-schema-doesn-t","errorCode":null,"errorMessage":"Not resolving subscription because schema doesn't have any fields defined for subscription operation.","messagePattern":"Not resolving subscription because schema doesn't have any fields defined for subscription operation\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/request.go","lineNumber":59,"sourceCode":"// 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\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}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/request.go#L41-L77","documentation":"The schema.Operation method rejects subscription requests when the GraphQL schema defines no fields under the Subscription root. GraphQL requires a matching root field for each operation type; without schema.Subscription there is nothing to resolve a subscription against.","triggerScenarios":"Sending a request whose single operation is `subscription { ... }` while the schema was generated without any subscription fields (s.schema.Subscription == nil).","commonSituations":"Client tries live queries/websockets against a schema that only defines query/mutation; schema was updated to remove subscriptions but clients still subscribe.","solutions":["Add subscription fields to the GraphQL schema and regenerate the handler.","Change the client to use query/mutation instead of subscription.","Guard the client: check the schema for a Subscription root before opening a subscription."],"exampleFix":"// before\nsubscription { newPost { id } } // schema has no subscription root\n// after (until subscriptions are added)\nquery { posts { id } }","handlingStrategy":"validation","validationCode":"// before subscribing, check the schema supports subscriptions\nif schema.Types().ForName(\"Subscription\") == nil {\n    return errors.New(\"server does not support subscriptions\")\n}","typeGuard":"func supportsSubscriptions(s Schema) bool {\n    return s.Types().ForName(\"Subscription\") != nil\n}","tryCatchPattern":"op, err := sch.Operation(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"Not resolving subscription\") {\n        // fall back to polling query or notify client subscriptions unsupported\n        return fallbackToQuery(req)\n    }\n    return err\n}","preventionTips":["Check schema capabilities before opening websocket subscriptions.","Keep client and server schema versions in sync.","If subscriptions were removed intentionally, update all clients.","Surface a clear capability error to client SDKs."],"tags":["graphql","subscription","schema"],"backgroundTag":"unsupported-operation","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}