nextauthjs/next-auth · error

Dgraph client error: Please provide a valid GraphQL endpoint

Error message

Dgraph client error: Please provide a valid GraphQL endpoint

What it means

After checking the API key, client() validates that params.endpoint is present and throws this error when it is missing/empty. The adapter needs the Dgraph GraphQL endpoint URL to issue queries and mutations. Like the API key check, it fires synchronously at adapter construction time.

Source

Thrown at packages/adapter-dgraph/src/lib/client.ts:40

   * [Using JWT and authorization claims](https://dgraph.io/docs/graphql/authorization/authorization-overview#using-jwts-and-authorization-claims)
   */
  authHeader?: string
}

export class DgraphClientError extends Error {
  name = "DgraphClientError"
  constructor(errors: any[], query: string, variables: any) {
    super(errors.map((error) => error.message).join("\n"))
    console.error({ query, variables })
  }
}

export function client(params: DgraphClientParams) {
  if (!params.authToken) {
    throw new Error("Dgraph client error: Please provide an API key")
  }
  if (!params.endpoint) {
    throw new Error(
      "Dgraph client error: Please provide a valid GraphQL endpoint"
    )
  }

  const {
    endpoint,
    authToken,
    jwtSecret,
    jwtAlgorithm = "HS256",
    authHeader = "Authorization",
  } = params
  const headers: HeadersInit = {
    "Content-Type": "application/json",
    "X-Auth-Token": authToken,
  }

  if (authHeader && jwtSecret) {
    headers[authHeader] = jwt.sign({ nextAuth: true }, jwtSecret, {

View on GitHub (pinned to a1a16a5a77)

Solutions

  1. Pass a valid GraphQL endpoint: DgraphAdapter({ endpoint: 'https://your-graph.us-west-2.aws.cloud.dgraph.io/graphql', authToken }).
  2. Set and verify the endpoint env var in your deployment environment.
  3. Ensure the URL points at the /graphql endpoint of your Dgraph instance.

Example fix

// before
const adapter = DgraphAdapter({ authToken: process.env.DGRAPH_AUTH_TOKEN })
// after
const adapter = DgraphAdapter({
  endpoint: process.env.DGRAPH_ENDPOINT,
  authToken: process.env.DGRAPH_AUTH_TOKEN,
})
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.DGRAPH_ENDPOINT?.startsWith('http')) {
  throw new Error('DGRAPH_ENDPOINT must be set to a valid GraphQL URL')
}

Type guard

function hasValidEndpoint(p: unknown): p is DgraphClientParams & { endpoint: string } {
  const ep = (p as any)?.endpoint
  return typeof ep === 'string' && ep.startsWith('http')
}

Try / catch

try {
  const adapter = DgraphAdapter(params)
} catch (e) {
  if (e instanceof Error && e.message.includes('valid GraphQL endpoint')) {
    // check DGRAPH_ENDPOINT is set and points at the /graphql route
  }
  throw e
}

Prevention

When it happens

Trigger: DgraphAdapter({ authToken }) without endpoint, endpoint: undefined from an unset env var, or a falsy value (empty string) passed as the endpoint.

Common situations: DGRAPH_ENDPOINT env var missing in the deployment environment, copying example code without filling in the endpoint, or switching from Dgraph Cloud URL to a self-hosted instance and forgetting the variable.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/fda432207ca92e82. Report an issue: GitHub.