dgraph-io/dgraph · error

error querying persisted queries

Error message

error querying persisted queries

What it means

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.

Source

Thrown at upgrade/change_v21.03.0.go:157

		}
	}
	fmt.Println("Successfully dropped the deprecated predicates")
	return nil
}

func upgradePersitentQuery() error {
	dg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds())
	defer cb()

	jwt, err := getAccessJwt()
	if err != nil {
		return errors.Wrap(err, "while getting jwt auth token")
	}

	// Get persisted queries.
	queryData := make(map[string][]pquery)
	if err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {
		return errors.Wrap(err, "error querying persisted queries")
	}

	// Update the schema with new indexer for persisted query.
	updatedSchema := `
		<dgraph.graphql.p_query>: string @index(sha256) .
		type <dgraph.graphql.persisted_query> {
			<dgraph.graphql.p_query>
		}
			`
	if err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {
		return fmt.Errorf("error updating the schema for persistent query, %w", err)
	}

	// Reinsert these queries. Note that upsert won't work here as 'dgraph.graphql.p_query' is
	// graphql reserved type.
	header := http.Header{}
	header.Set("X-Dgraph-AccessToken", jwt.AccessJwt)
	header.Set("X-Dgraph-AuthToken", Upgrade.Conf.GetString(authToken))

View on GitHub (pinned to 759e242be6)

Solutions

  1. Confirm the GraphQL schema/predicates exist in the cluster before upgrading.
  2. Check Alpha logs for query execution errors and fix the root cause.
  3. Re-authenticate if the JWT expired and re-run the upgrade.
  4. Verify connectivity to the Alpha HTTP endpoint used by the upgrade tool.
Defensive patterns

Strategy: retry

Validate before calling

curl -s http://localhost:8080/query -XPOST -d '{ q(func: type(dgraph.graphql.persisted_query)) { uid } }'

Try / catch

if err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {
	// retry once after re-auth, then surface wrapped error
	return errors.Wrap(err, "error querying persisted queries")
}

Prevention

When it happens

Trigger: getQueryResult fails executing the DQL query on dgraph.graphql.persisted_query — Alpha unreachable, query rejected, or malformed/absent GraphQL layer data.

Common situations: Running the upgrade against a cluster without the GraphQL layer schema present; network issues; ACL token expired mid-run; query endpoint returning HTTP errors.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/35096889a55f5681. Report an issue: GitHub.