{"record":{"id":"3420d3816e8ee3c4","repo":"hasura/graphql-engine","slug":"couldn-t-find-relationship-field-relationship-f","errorCode":null,"errorMessage":"Couldn't find relationship ${field.relationship} for field ${fieldName} on target ${JSON.stringify(target)}","messagePattern":"Couldn't find relationship (.+?) for field (.+?) on target (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"dc-agents/sqlite/src/query.ts","lineNumber":136,"sourceCode":"  return escapeTableName(getTableNameSansSchema(tableName));\n}\n\nexport function json_object(\n  all_relationships: Relationships[],\n  fields: Fields,\n  target: Target,\n  tableAlias: string,\n): string {\n  const result = Object.entries(fields)\n    .map(([fieldName, field]) => {\n      switch (field.type) {\n        case 'column':\n          return `${escapeString(fieldName)}, ${escapeIdentifier(field.column)}`;\n        case 'relationship':\n          const relationships = find_relationships(all_relationships, target);\n          const rel = relationships.relationships[field.relationship];\n          if (rel === undefined) {\n            throw new Error(\n              `Couldn't find relationship ${field.relationship} for field ${fieldName} on target ${JSON.stringify(target)}`,\n            );\n          }\n          return `'${fieldName}', ${relationship(all_relationships, rel, field, tableAlias)}`;\n        case 'object':\n          throw new Error('Unsupported field type \"object\"');\n        case 'array':\n          throw new Error('Unsupported field type \"array\"');\n        default:\n          return unreachable(field['type']);\n      }\n    })\n    .join(', ');\n\n  return tag('json_object', `JSON_OBJECT(${result})`);\n}\n\nexport function where_clause(","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/sqlite/src/query.ts#L118-L154","documentation":"While building the JSON_OBJECT projection for a query, the agent looks up the relationship named by `field.relationship` via find_relationships against the tracked relationships for the target. If the target has no relationship with that name, the field cannot be expanded and a plain Error is thrown embedding the relationship name, field name, and target JSON.","triggerScenarios":"Requesting a field whose definition references `relationship: 'X'` when the agent's relationship set for that target has no entry 'X' — e.g. stale field metadata, a typo'd relationship name, or querying a table whose FK-derived relationships differ from what the client assumes.","commonSituations":"Client-side schema/metadata cache is stale after the database schema changed (FK dropped or renamed); hand-written queries referencing relationships that only exist in another environment; drift between the agent's introspected schema and the client's model.","solutions":["Fetch the agent's schema/relationships endpoint and confirm the relationship exists for that target","Fix the field definition to reference an existing relationship name, or drop the field","If the relationship should exist, verify the underlying FOREIGN KEY constraint is present in SQLite (PRAGMA foreign_key_list) so the agent introspects it","Clear and re-sync client metadata caches"],"exampleFix":"// before\n{ fields: { artist: { type: 'relationship', relationship: 'artistRef', args: {...} } } }\n// after (use the relationship name the agent reports)\n{ fields: { artist: { type: 'relationship', relationship: 'artist', args: {...} } } }","handlingStrategy":"validation","validationCode":"const rels = await fetchSchemaRelationships(agentUrl, target); if (!(fieldName in rels)) throw new Error(`Unknown relationship ${fieldName}`);","typeGuard":"const hasRelationship = (rels: Record<string, unknown>, name: string) => Object.prototype.hasOwnProperty.call(rels, name);","tryCatchPattern":"try { await agent.query(q); } catch (e) { if (/Couldn't find relationship/.test(String(e))) await refreshLocalSchemaCache(); throw e; }","preventionTips":["Cache the agent's schema/relationship response and validate field.relationship names against it","Re-sync metadata caches after DB schema changes","Verify FKs exist with PRAGMA foreign_key_list when a relationship is missing"],"tags":["sqlite","relationship","metadata","query-builder"],"backgroundTag":"relationship-not-found","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}