{"record":{"id":"f0eb15a229795550","repo":"dgraph-io/dgraph","slug":"error-querying-graphql-schema","errorCode":null,"errorMessage":"error querying graphql schema","messagePattern":"error querying graphql schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":234,"sourceCode":"\t\tuid, err := strconv.ParseUint(cors.UID, 0, 64)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif uid > maxUid {\n\t\t\tmaxUid = uid\n\t\t\tif len(cors.Cors) == 1 && cors.Cors[0] == \"*\" {\n\t\t\t\t// No need to update the GraphQL schema if all origins are allowed.\n\t\t\t\tcorsList = corsList[:0]\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tcorsList = cors.Cors\n\t\t}\n\t}\n\n\t// Get GraphQL schema.\n\tschemaData := make(map[string][]sch)\n\tif err := getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil {\n\t\treturn errors.Wrap(err, \"error querying graphql schema\")\n\t}\n\n\tvar gqlSchema string\n\tmaxUid = 0\n\tfor _, schema := range schemaData[\"schema\"] {\n\t\tuid, err := strconv.ParseUint(schema.UID, 0, 64)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif uid > maxUid {\n\t\t\tmaxUid = uid\n\t\t\tgqlSchema = schema.GQLSchema\n\t\t}\n\t}\n\n\t// Update the GraphQL schema.\n\tif err := updateGQLSchema(jwt, gqlSchema, corsList); err != nil {\n\t\treturn err","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L216-L252","documentation":"upgradeCORS queries the GraphQL schema via querySchema_v21_03_0 to rewrite it with merged CORS headers. Failure is wrapped as 'error querying graphql schema'. The tool could not fetch the stored GraphQL schema (dgraph.graphql.schema) from the cluster.","triggerScenarios":"getQueryResult fails on the schema query — Alpha unreachable, GraphQL schema predicate absent, or response not parseable into map[string][]sch.","commonSituations":"Clusters with no GraphQL schema ever deployed; expired auth token; HTTP/network failures; malformed stored schema data from earlier partial migrations.","solutions":["Confirm a GraphQL schema exists (query dgraph.graphql.schema via DQL).","Re-authenticate and re-run the upgrade if the token expired.","Fix connectivity/HTTP issues to Alpha and retry.","Inspect Alpha logs for the underlying query failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"curl -s http://localhost:8080/query -XPOST -d '{ schema(func: has(dgraph.graphql.schema)) { uid dgraph.graphql.schema } }'","typeGuard":null,"tryCatchPattern":"if err := getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil {\n\t// fetch the stored schema manually if this fails, then retry\n\treturn errors.Wrap(err, \"error querying graphql schema\")\n}","preventionTips":["Ensure a GraphQL schema is deployed before upgrading","Keep the JWT fresh for the duration of the migration","Snapshot/backup the schema before running migrations"],"tags":["dgraph","upgrade","graphql","schema","query"],"backgroundTag":"dql-query-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}