{"record":{"id":"fda432207ca92e82","repo":"nextauthjs/next-auth","slug":"dgraph-client-error-please-provide-a-valid-graphq","errorCode":null,"errorMessage":"Dgraph client error: Please provide a valid GraphQL endpoint","messagePattern":"Dgraph client error: Please provide a valid GraphQL endpoint","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-dgraph/src/lib/client.ts","lineNumber":40,"sourceCode":"   * [Using JWT and authorization claims](https://dgraph.io/docs/graphql/authorization/authorization-overview#using-jwts-and-authorization-claims)\n   */\n  authHeader?: string\n}\n\nexport class DgraphClientError extends Error {\n  name = \"DgraphClientError\"\n  constructor(errors: any[], query: string, variables: any) {\n    super(errors.map((error) => error.message).join(\"\\n\"))\n    console.error({ query, variables })\n  }\n}\n\nexport function client(params: DgraphClientParams) {\n  if (!params.authToken) {\n    throw new Error(\"Dgraph client error: Please provide an API key\")\n  }\n  if (!params.endpoint) {\n    throw new Error(\n      \"Dgraph client error: Please provide a valid GraphQL endpoint\"\n    )\n  }\n\n  const {\n    endpoint,\n    authToken,\n    jwtSecret,\n    jwtAlgorithm = \"HS256\",\n    authHeader = \"Authorization\",\n  } = params\n  const headers: HeadersInit = {\n    \"Content-Type\": \"application/json\",\n    \"X-Auth-Token\": authToken,\n  }\n\n  if (authHeader && jwtSecret) {\n    headers[authHeader] = jwt.sign({ nextAuth: true }, jwtSecret, {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-dgraph/src/lib/client.ts#L22-L58","documentation":"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.","triggerScenarios":"DgraphAdapter({ authToken }) without endpoint, endpoint: undefined from an unset env var, or a falsy value (empty string) passed as the endpoint.","commonSituations":"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.","solutions":["Pass a valid GraphQL endpoint: DgraphAdapter({ endpoint: 'https://your-graph.us-west-2.aws.cloud.dgraph.io/graphql', authToken }).","Set and verify the endpoint env var in your deployment environment.","Ensure the URL points at the /graphql endpoint of your Dgraph instance."],"exampleFix":"// before\nconst adapter = DgraphAdapter({ authToken: process.env.DGRAPH_AUTH_TOKEN })\n// after\nconst adapter = DgraphAdapter({\n  endpoint: process.env.DGRAPH_ENDPOINT,\n  authToken: process.env.DGRAPH_AUTH_TOKEN,\n})","handlingStrategy":"validation","validationCode":"if (!process.env.DGRAPH_ENDPOINT?.startsWith('http')) {\n  throw new Error('DGRAPH_ENDPOINT must be set to a valid GraphQL URL')\n}","typeGuard":"function hasValidEndpoint(p: unknown): p is DgraphClientParams & { endpoint: string } {\n  const ep = (p as any)?.endpoint\n  return typeof ep === 'string' && ep.startsWith('http')\n}","tryCatchPattern":"try {\n  const adapter = DgraphAdapter(params)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('valid GraphQL endpoint')) {\n    // check DGRAPH_ENDPOINT is set and points at the /graphql route\n  }\n  throw e\n}","preventionTips":["Set DGRAPH_ENDPOINT per environment and point it at the /graphql route","Sanity-check the URL with a curl/health query before deploying","Keep endpoint and authToken configured together as a pair","Use a config module that validates both at boot"],"tags":["configuration","endpoint","dgraph","env"],"backgroundTag":"missing-env-var","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}