Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- 9000:8000

contember-engine:
image: contember/engine:2.2.0-alpha.17
image: contember/engine:2.2.0-alpha.19
env:
NODE_ENV: development
CONTEMBER_PORT: "4000"
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
-e CONTEMBER_PROJECT_NAME=example \
-v ${{ github.workspace }}:/src \
-w /src/packages/example \
contember/cli:2.2.0-alpha.17 \
contember/cli:2.2.0-alpha.19 \
migrations:execute --yes
CONTEMBER_API_URL=http://localhost:1581 CONTEMBER_API_TOKEN=0000000000000000000000000000000000000000 bun run packages/example/seed.ts

Expand Down
41 changes: 21 additions & 20 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
contember-engine:
image: contember/engine:2.2.0-alpha.17
image: contember/engine:2.2.0-alpha.19

environment:
NODE_ENV: 'development'
Expand Down Expand Up @@ -43,7 +43,7 @@ services:
condition: service_healthy

contember-cli:
image: contember/cli:2.2.0-alpha.17
image: contember/cli:2.2.0-alpha.19
user: '1000:1000'

deploy:
Expand Down
6 changes: 3 additions & 3 deletions packages/bindx-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
],
"license": "MIT",
"dependencies": {
"@contember/graphql-builder": "2.2.0-alpha.17",
"@contember/graphql-client": "2.2.0-alpha.17",
"@contember/schema": "2.2.0-alpha.17"
"@contember/graphql-builder": "2.2.0-alpha.19",
"@contember/graphql-client": "2.2.0-alpha.19",
"@contember/schema": "2.2.0-alpha.19"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/bindx-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
],
"license": "MIT",
"dependencies": {
"@contember/schema": "2.2.0-alpha.17",
"@contember/schema-utils": "2.2.0-alpha.17"
"@contember/schema": "2.2.0-alpha.19",
"@contember/schema-utils": "2.2.0-alpha.19"
},
"devDependencies": {
"@types/node": "^25.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/bindx-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@contember/bindx": "workspace:*",
"@contember/bindx-client": "workspace:*",
"@contember/graphql-client": "2.2.0-alpha.17",
"@contember/graphql-client": "2.2.0-alpha.19",
"@radix-ui/primitive": "^1.1.3",
"@radix-ui/react-slot": "^1.2.4"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/bindx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"license": "MIT",
"dependencies": {
"@contember/bindx-client": "workspace:*",
"@contember/graphql-client": "2.2.0-alpha.17"
"@contember/graphql-client": "2.2.0-alpha.19",
"@contember/schema": "2.2.0-alpha.19"
},
"repository": {
"type": "git",
Expand Down
38 changes: 15 additions & 23 deletions packages/bindx/src/errors/errorPathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type { SchemaRegistry } from '../schema/SchemaRegistry.js'
import type { SnapshotStore } from '../store/SnapshotStore.js'
import type { PathElement, ContemberMutationResult } from './pathMapper.js'
import { createServerError, type ServerError } from './types.js'
import { createServerError, isExecutionErrorType, type ExecutionErrorType, type ServerError } from './types.js'

/**
* The resolved target of an error path.
Expand Down Expand Up @@ -175,28 +175,20 @@ function resolveHasManyItemId(
* Converts error type string to a user-friendly error code.
*/
function getErrorCode(errorType?: string): string | undefined {
if (!errorType) return undefined

switch (errorType) {
case 'UniqueConstraintViolation':
return 'UNIQUE_CONSTRAINT'
case 'NotNullConstraintViolation':
return 'NOT_NULL'
case 'ForeignKeyConstraintViolation':
return 'FOREIGN_KEY'
case 'NotFoundOrDenied':
return 'NOT_FOUND'
case 'NonUniqueWhereInput':
return 'NON_UNIQUE_WHERE'
case 'InvalidDataInput':
return 'INVALID_DATA'
case 'SqlError':
return 'SQL_ERROR'
case 'ResourceExhausted':
return 'RESOURCE_EXHAUSTED'
default:
return undefined
}
if (errorType === undefined || !isExecutionErrorType(errorType)) return undefined
return executionErrorCodes[errorType]
}

const executionErrorCodes: Record<ExecutionErrorType, string> = {
UniqueConstraintViolation: 'UNIQUE_CONSTRAINT',
NotNullConstraintViolation: 'NOT_NULL',
ForeignKeyConstraintViolation: 'FOREIGN_KEY',
CheckConstraintViolation: 'CHECK_CONSTRAINT',
NotFoundOrDenied: 'NOT_FOUND',
NonUniqueWhereInput: 'NON_UNIQUE_WHERE',
InvalidDataInput: 'INVALID_DATA',
SqlError: 'SQL_ERROR',
ResourceExhausted: 'RESOURCE_EXHAUSTED',
}

/**
Expand Down
38 changes: 17 additions & 21 deletions packages/bindx/src/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ExecutionErrorTypes: Record<ExecutionErrorType, ExecutionErrorType>
NotNullConstraintViolation: 'NotNullConstraintViolation',
UniqueConstraintViolation: 'UniqueConstraintViolation',
ForeignKeyConstraintViolation: 'ForeignKeyConstraintViolation',
CheckConstraintViolation: 'CheckConstraintViolation',
NotFoundOrDenied: 'NotFoundOrDenied',
NonUniqueWhereInput: 'NonUniqueWhereInput',
InvalidDataInput: 'InvalidDataInput',
Expand All @@ -32,7 +33,7 @@ export const ExecutionErrorTypes: Record<ExecutionErrorType, ExecutionErrorType>
* Checks if a string is a valid ExecutionErrorType.
*/
export function isExecutionErrorType(value: string): value is ExecutionErrorType {
return value in ExecutionErrorTypes
return Object.hasOwn(ExecutionErrorTypes, value)
}

/**
Expand All @@ -50,26 +51,21 @@ export type ErrorCategory = 'validation' | 'constraint' | 'not_found' | 'resourc
* - 'unknown': Unclassified errors
*/
export function classifyError(errorType?: string): ErrorCategory {
if (!errorType) return 'unknown'

switch (errorType) {
case 'NotNullConstraintViolation':
case 'UniqueConstraintViolation':
case 'ForeignKeyConstraintViolation':
return 'constraint'
case 'InvalidDataInput':
case 'NonUniqueWhereInput':
return 'validation'
case 'NotFoundOrDenied':
return 'not_found'
case 'ResourceExhausted':
return 'resource_limit'
case 'SqlError':
// SQL errors could be transient (deadlock, connection issues) or permanent
return 'transient'
default:
return 'unknown'
}
if (errorType === undefined || !isExecutionErrorType(errorType)) return 'unknown'
return executionErrorCategories[errorType]
}

const executionErrorCategories: Record<ExecutionErrorType, ErrorCategory> = {
NotNullConstraintViolation: 'constraint',
UniqueConstraintViolation: 'constraint',
ForeignKeyConstraintViolation: 'constraint',
CheckConstraintViolation: 'constraint',
InvalidDataInput: 'validation',
NonUniqueWhereInput: 'validation',
NotFoundOrDenied: 'not_found',
ResourceExhausted: 'resource_limit',
// SQL errors could be transient (deadlock, connection issues) or permanent
SqlError: 'transient',
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/example/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "0.0.0",
"type": "module",
"devDependencies": {
"@contember/schema": "2.2.0-alpha.17",
"@contember/schema-definition": "2.2.0-alpha.17"
"@contember/schema": "2.2.0-alpha.19",
"@contember/schema-definition": "2.2.0-alpha.19"
},
"dependencies": {
"graphql": "^16.8.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"@contember/bindx-repeater": "workspace:*",
"@contember/bindx-uploader": "workspace:*",
"@contember/bindx-react": "workspace:*",
"@contember/client-content": "2.2.0-alpha.17",
"@contember/graphql-client": "2.2.0-alpha.17",
"@contember/schema": "2.2.0-alpha.17",
"@contember/schema-definition": "2.2.0-alpha.17",
"@contember/client-content": "2.2.0-alpha.19",
"@contember/graphql-client": "2.2.0-alpha.19",
"@contember/schema": "2.2.0-alpha.19",
"@contember/schema-definition": "2.2.0-alpha.19",
"@tailwindcss/vite": "^4.2.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/errors/errorClassification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('error classification', () => {
['NotNullConstraintViolation', 'constraint'],
['UniqueConstraintViolation', 'constraint'],
['ForeignKeyConstraintViolation', 'constraint'],
['CheckConstraintViolation', 'constraint'],
['InvalidDataInput', 'validation'],
['NonUniqueWhereInput', 'validation'],
['NotFoundOrDenied', 'not_found'],
Expand All @@ -35,6 +36,10 @@ describe('error classification', () => {
test('should return unknown for undefined error type', () => {
expect(classifyError(undefined)).toBe('unknown')
})

test.each(['FutureEngineError', 'toString', 'constructor'])('should return unknown for unrecognised type %s', errorType => {
expect(classifyError(errorType)).toBe('unknown')
})
})

describe('isRetryableCategory', () => {
Expand All @@ -55,6 +60,7 @@ describe('error classification', () => {
expect(isExecutionErrorType('NotNullConstraintViolation')).toBe(true)
expect(isExecutionErrorType('UniqueConstraintViolation')).toBe(true)
expect(isExecutionErrorType('ForeignKeyConstraintViolation')).toBe(true)
expect(isExecutionErrorType('CheckConstraintViolation')).toBe(true)
expect(isExecutionErrorType('NotFoundOrDenied')).toBe(true)
expect(isExecutionErrorType('NonUniqueWhereInput')).toBe(true)
expect(isExecutionErrorType('InvalidDataInput')).toBe(true)
Expand All @@ -66,15 +72,17 @@ describe('error classification', () => {
expect(isExecutionErrorType('UnknownError')).toBe(false)
expect(isExecutionErrorType('')).toBe(false)
expect(isExecutionErrorType('notNullConstraintViolation')).toBe(false) // Wrong case
expect(isExecutionErrorType('toString')).toBe(false)
})
})

describe('ExecutionErrorTypes', () => {
test('should contain all error types', () => {
expect(Object.keys(ExecutionErrorTypes)).toHaveLength(8)
expect(Object.keys(ExecutionErrorTypes)).toHaveLength(9)
expect(ExecutionErrorTypes.NotNullConstraintViolation).toBe('NotNullConstraintViolation')
expect(ExecutionErrorTypes.UniqueConstraintViolation).toBe('UniqueConstraintViolation')
expect(ExecutionErrorTypes.ForeignKeyConstraintViolation).toBe('ForeignKeyConstraintViolation')
expect(ExecutionErrorTypes.CheckConstraintViolation).toBe('CheckConstraintViolation')
expect(ExecutionErrorTypes.NotFoundOrDenied).toBe('NotFoundOrDenied')
expect(ExecutionErrorTypes.NonUniqueWhereInput).toBe('NonUniqueWhereInput')
expect(ExecutionErrorTypes.InvalidDataInput).toBe('InvalidDataInput')
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/errors/errorPathResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,30 @@ describe('errorPathResolver', () => {
expect(resolved[0]!.error.retryable).toBe(false)
})

test('should report a check constraint violation as a non-retryable entity-level constraint error', () => {
const store = new SnapshotStore()

const mutationResult: ContemberMutationResult = {
ok: false,
errorMessage: null,
errors: [{
paths: [],
message: 'Check constraint "ratingRange" on entity Article violated',
type: 'CheckConstraintViolation',
}],
validation: { valid: true, errors: [] },
}

const resolved = resolveAllErrors(mutationResult, 'Article', 'a-1', createContext(store))

expect(resolved).toHaveLength(1)
expect(resolved[0]!.target).toEqual({ entityType: 'Article', entityId: 'a-1', type: 'entity' })
expect(resolved[0]!.error.type).toBe('CheckConstraintViolation')
expect(resolved[0]!.error.code).toBe('CHECK_CONSTRAINT')
expect(resolved[0]!.error.category).toBe('constraint')
expect(resolved[0]!.error.retryable).toBe(false)
})

test('should resolve multiple errors to different entities', () => {
const store = new SnapshotStore()
store.getOrCreateRelation('Article', 'a-1', 'author', {
Expand Down
Loading