(schema: SchemaDef, modelOrType: string, field: string)
| 80 | } |
| 81 | |
| 82 | export function requireField(schema: SchemaDef, modelOrType: string, field: string) { |
| 83 | const modelDef = getModel(schema, modelOrType); |
| 84 | if (modelDef) { |
| 85 | if (!modelDef.fields[field]) { |
| 86 | throw createInternalError(`Field "${field}" not found in model "${modelOrType}"`, modelOrType); |
| 87 | } else { |
| 88 | return modelDef.fields[field]; |
| 89 | } |
| 90 | } |
| 91 | const typeDef = getTypeDef(schema, modelOrType); |
| 92 | if (typeDef) { |
| 93 | if (!typeDef.fields[field]) { |
| 94 | throw createInternalError(`Field "${field}" not found in type "${modelOrType}"`, modelOrType); |
| 95 | } else { |
| 96 | return typeDef.fields[field]; |
| 97 | } |
| 98 | } |
| 99 | throw createInternalError(`Model or type "${modelOrType}" not found in schema`, modelOrType); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Gets all model fields, by default non-relation, non-computed, non-inherited, non-unsupported fields only. |
no test coverage detected