{"record":{"id":"35096889a55f5681","repo":"dgraph-io/dgraph","slug":"error-querying-persisted-queries","errorCode":null,"errorMessage":"error querying persisted queries","messagePattern":"error querying persisted queries","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":157,"sourceCode":"\t\t}\n\t}\n\tfmt.Println(\"Successfully dropped the deprecated predicates\")\n\treturn nil\n}\n\nfunc upgradePersitentQuery() error {\n\tdg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds())\n\tdefer cb()\n\n\tjwt, err := getAccessJwt()\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"while getting jwt auth token\")\n\t}\n\n\t// Get persisted queries.\n\tqueryData := make(map[string][]pquery)\n\tif err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {\n\t\treturn errors.Wrap(err, \"error querying persisted queries\")\n\t}\n\n\t// Update the schema with new indexer for persisted query.\n\tupdatedSchema := `\n\t\t<dgraph.graphql.p_query>: string @index(sha256) .\n\t\ttype <dgraph.graphql.persisted_query> {\n\t\t\t<dgraph.graphql.p_query>\n\t\t}\n\t\t\t`\n\tif err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {\n\t\treturn fmt.Errorf(\"error updating the schema for persistent query, %w\", err)\n\t}\n\n\t// Reinsert these queries. Note that upsert won't work here as 'dgraph.graphql.p_query' is\n\t// graphql reserved type.\n\theader := http.Header{}\n\theader.Set(\"X-Dgraph-AccessToken\", jwt.AccessJwt)\n\theader.Set(\"X-Dgraph-AuthToken\", Upgrade.Conf.GetString(authToken))","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L139-L175","documentation":"After obtaining a JWT, upgradePersitentQuery runs queryPersistedQuery_v21_03_0 via getQueryResult. Failure is wrapped as 'error querying persisted queries'. The Dgraph query for existing persisted queries failed or returned an unexpected response.","triggerScenarios":"getQueryResult fails executing the DQL query on dgraph.graphql.persisted_query — Alpha unreachable, query rejected, or malformed/absent GraphQL layer data.","commonSituations":"Running the upgrade against a cluster without the GraphQL layer schema present; network issues; ACL token expired mid-run; query endpoint returning HTTP errors.","solutions":["Confirm the GraphQL schema/predicates exist in the cluster before upgrading.","Check Alpha logs for query execution errors and fix the root cause.","Re-authenticate if the JWT expired and re-run the upgrade.","Verify connectivity to the Alpha HTTP endpoint used by the upgrade tool."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"curl -s http://localhost:8080/query -XPOST -d '{ q(func: type(dgraph.graphql.persisted_query)) { uid } }'","typeGuard":null,"tryCatchPattern":"if err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {\n\t// retry once after re-auth, then surface wrapped error\n\treturn errors.Wrap(err, \"error querying persisted queries\")\n}","preventionTips":["Confirm the GraphQL layer is initialized before upgrading","Re-authenticate on long migrations so the JWT does not expire","Test the DQL query manually first"],"tags":["dgraph","upgrade","dql","query","graphql"],"backgroundTag":"dql-query-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}