@contember/engine-content-api 1.3.0-alpha.1 → 1.3.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ExecutionContainer.d.ts +141 -0
- package/dist/src/ExecutionContainer.d.ts.map +1 -0
- package/dist/src/ExecutionContainer.js +84 -0
- package/dist/src/ExecutionContainer.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mapper/ColumnValue.d.ts +2 -2
- package/dist/src/mapper/ColumnValue.d.ts.map +1 -1
- package/dist/src/mapper/EventManager.d.ts +86 -0
- package/dist/src/mapper/EventManager.d.ts.map +1 -0
- package/dist/src/mapper/EventManager.js +118 -0
- package/dist/src/mapper/EventManager.js.map +1 -0
- package/dist/src/mapper/JunctionTableManager.d.ts +12 -11
- package/dist/src/mapper/JunctionTableManager.d.ts.map +1 -1
- package/dist/src/mapper/JunctionTableManager.js +20 -8
- package/dist/src/mapper/JunctionTableManager.js.map +1 -1
- package/dist/src/mapper/Mapper.d.ts +11 -6
- package/dist/src/mapper/Mapper.d.ts.map +1 -1
- package/dist/src/mapper/Mapper.js +34 -17
- package/dist/src/mapper/Mapper.js.map +1 -1
- package/dist/src/mapper/MapperFactory.d.ts +33 -0
- package/dist/src/mapper/MapperFactory.d.ts.map +1 -0
- package/dist/src/mapper/MapperFactory.js +40 -0
- package/dist/src/mapper/MapperFactory.js.map +1 -0
- package/dist/src/mapper/Result.d.ts +3 -2
- package/dist/src/mapper/Result.d.ts.map +1 -1
- package/dist/src/mapper/Result.js +2 -1
- package/dist/src/mapper/Result.js.map +1 -1
- package/dist/src/mapper/delete/DeleteExecutor.d.ts.map +1 -1
- package/dist/src/mapper/delete/DeleteExecutor.js +41 -1
- package/dist/src/mapper/delete/DeleteExecutor.js.map +1 -1
- package/dist/src/mapper/index.d.ts +3 -1
- package/dist/src/mapper/index.d.ts.map +1 -1
- package/dist/src/mapper/index.js +3 -1
- package/dist/src/mapper/index.js.map +1 -1
- package/dist/src/mapper/insert/InsertBuilder.d.ts +2 -2
- package/dist/src/mapper/insert/InsertBuilder.d.ts.map +1 -1
- package/dist/src/mapper/insert/InsertBuilder.js +8 -2
- package/dist/src/mapper/insert/InsertBuilder.js.map +1 -1
- package/dist/src/mapper/insert/Inserter.js +3 -3
- package/dist/src/mapper/insert/Inserter.js.map +1 -1
- package/dist/src/mapper/select/OrderByHelper.d.ts +1 -1
- package/dist/src/mapper/select/OrderByHelper.d.ts.map +1 -1
- package/dist/src/mapper/select/OrderByHelper.js +3 -1
- package/dist/src/mapper/select/OrderByHelper.js.map +1 -1
- package/dist/src/mapper/select/RelationFetcher.js +2 -2
- package/dist/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/src/mapper/update/UpdateBuilder.d.ts +4 -4
- package/dist/src/mapper/update/UpdateBuilder.d.ts.map +1 -1
- package/dist/src/mapper/update/UpdateBuilder.js +26 -8
- package/dist/src/mapper/update/UpdateBuilder.js.map +1 -1
- package/dist/src/mapper/update/UpdateBuilderFactory.d.ts +1 -1
- package/dist/src/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
- package/dist/src/mapper/update/UpdateBuilderFactory.js +2 -2
- package/dist/src/mapper/update/UpdateBuilderFactory.js.map +1 -1
- package/dist/src/mapper/update/Updater.d.ts.map +1 -1
- package/dist/src/mapper/update/Updater.js +6 -10
- package/dist/src/mapper/update/Updater.js.map +1 -1
- package/dist/src/resolvers/GraphQlQueryAstFactory.d.ts +1 -3
- package/dist/src/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
- package/dist/src/resolvers/GraphQlQueryAstFactory.js +1 -4
- package/dist/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
- package/dist/src/resolvers/MutationResolver.d.ts +1 -4
- package/dist/src/resolvers/MutationResolver.d.ts.map +1 -1
- package/dist/src/resolvers/MutationResolver.js +9 -11
- package/dist/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/src/resolvers/ReadResolver.d.ts +1 -3
- package/dist/src/resolvers/ReadResolver.d.ts.map +1 -1
- package/dist/src/resolvers/ReadResolver.js +6 -10
- package/dist/src/resolvers/ReadResolver.js.map +1 -1
- package/dist/src/resolvers/ValidationResolver.d.ts +1 -3
- package/dist/src/resolvers/ValidationResolver.d.ts.map +1 -1
- package/dist/src/resolvers/ValidationResolver.js +3 -4
- package/dist/src/resolvers/ValidationResolver.js.map +1 -1
- package/dist/src/resolvers/index.d.ts +0 -1
- package/dist/src/resolvers/index.d.ts.map +1 -1
- package/dist/src/resolvers/index.js +0 -1
- package/dist/src/resolvers/index.js.map +1 -1
- package/dist/src/schema/CustomTypesProvider.d.ts.map +1 -1
- package/dist/src/schema/CustomTypesProvider.js +1 -23
- package/dist/src/schema/CustomTypesProvider.js.map +1 -1
- package/dist/src/schema/MutationProvider.js +4 -4
- package/dist/src/schema/MutationProvider.js.map +1 -1
- package/dist/src/schema/QueryProvider.js +3 -3
- package/dist/src/schema/QueryProvider.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types.d.ts +2 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tests/cases/bugs/bug-update-by-nested-unique.test.js +3 -5
- package/dist/tests/cases/bugs/bug-update-by-nested-unique.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js +2 -2
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/bug-freeze-connect-missing-one.test.js +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/bug-freeze-connect-missing-one.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/deferedConstraints.test.js +45 -45
- package/dist/tests/cases/integration/graphQlDb/update/deferedConstraints.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/failedDelete.test.js +5 -5
- package/dist/tests/cases/integration/graphQlDb/update/failedDelete.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/invalidInput.test.js +2 -2
- package/dist/tests/cases/integration/graphQlDb/update/invalidInput.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/nullChecksNotNull.test.js +7 -7
- package/dist/tests/cases/integration/graphQlDb/update/nullChecksNotNull.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/nullChecksNullable.test.js +7 -7
- package/dist/tests/cases/integration/graphQlDb/update/nullChecksNullable.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlDb/update/uniqueConstraint.test.js +2 -2
- package/dist/tests/cases/integration/graphQlDb/update/uniqueConstraint.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/oneHasMany/connect.test.js +3 -3
- package/dist/tests/cases/integration/graphQlRequests/insert/oneHasMany/connect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.js +67 -0
- package/dist/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.js.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js +6 -18
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/additionalFilter.test.js +3 -4
- package/dist/tests/cases/integration/graphQlRequests/update/additionalFilter.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/basic/columnUpdate.test.js +3 -8
- package/dist/tests/cases/integration/graphQlRequests/update/basic/columnUpdate.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/update.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/upsert.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/update.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/upsert.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/connect.test.js +3 -10
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/connect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/create.test.js +3 -10
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/create.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/disconnect.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/disconnect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/update.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/upsert.test.js +6 -18
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasOne/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connect.test.js +3 -11
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/disconnect.test.js +3 -8
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/disconnect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/update.test.js +3 -6
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/upsert.test.js +3 -6
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/connect.test.js +15 -50
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/connect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/create.test.js +3 -10
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/create.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/disconnect.test.js +3 -10
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/disconnect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/update.test.js +3 -6
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/upsert.test.js +3 -7
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connect.test.js +12 -32
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connectOrCreate.test.js +3 -3
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connectOrCreate.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/create.test.js +6 -20
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/create.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/disconnect.test.js +3 -10
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/disconnect.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/update.test.js +3 -9
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/update.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/upsert.test.js +6 -19
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/upsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/queryPortal.test.js +6 -8
- package/dist/tests/cases/integration/graphQlRequests/update/queryPortal.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/transaction.test.js +9 -24
- package/dist/tests/cases/integration/graphQlRequests/update/transaction.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/upsert/basicUpsert.test.js +3 -7
- package/dist/tests/cases/integration/graphQlRequests/upsert/basicUpsert.test.js.map +1 -1
- package/dist/tests/cases/unit/orderbyHelper.test.js +11 -0
- package/dist/tests/cases/unit/orderbyHelper.test.js.map +1 -1
- package/dist/tests/src/test.d.ts +1 -0
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/src/test.js +34 -6
- package/dist/tests/src/test.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/ExecutionContainer.ts +204 -0
- package/src/index.ts +24 -1
- package/src/mapper/ColumnValue.ts +2 -2
- package/src/mapper/EventManager.ts +158 -0
- package/src/mapper/JunctionTableManager.ts +50 -32
- package/src/mapper/Mapper.ts +39 -21
- package/src/mapper/MapperFactory.ts +67 -0
- package/src/mapper/Result.ts +2 -1
- package/src/mapper/delete/DeleteExecutor.ts +42 -1
- package/src/mapper/index.ts +3 -1
- package/src/mapper/insert/InsertBuilder.ts +12 -2
- package/src/mapper/insert/Inserter.ts +3 -3
- package/src/mapper/select/OrderByHelper.ts +2 -1
- package/src/mapper/select/RelationFetcher.ts +2 -2
- package/src/mapper/update/UpdateBuilder.ts +30 -7
- package/src/mapper/update/UpdateBuilderFactory.ts +2 -2
- package/src/mapper/update/Updater.ts +6 -11
- package/src/resolvers/GraphQlQueryAstFactory.ts +1 -2
- package/src/resolvers/MutationResolver.ts +12 -13
- package/src/resolvers/ReadResolver.ts +5 -9
- package/src/resolvers/ValidationResolver.ts +2 -4
- package/src/resolvers/index.ts +0 -1
- package/src/schema/CustomTypesProvider.ts +2 -27
- package/src/schema/MutationProvider.ts +4 -4
- package/src/schema/QueryProvider.ts +3 -3
- package/src/tsconfig.json +7 -21
- package/src/types.ts +2 -3
- package/tests/cases/bugs/bug-update-by-nested-unique.test.ts +3 -5
- package/tests/cases/integration/graphQlDb/insert/insertSequence.test.ts +2 -2
- package/tests/cases/integration/graphQlDb/update/bug-freeze-connect-missing-one.test.ts +1 -1
- package/tests/cases/integration/graphQlDb/update/deferedConstraints.test.ts +9 -9
- package/tests/cases/integration/graphQlDb/update/failedDelete.test.ts +3 -3
- package/tests/cases/integration/graphQlDb/update/invalidInput.test.ts +2 -2
- package/tests/cases/integration/graphQlDb/update/nullChecksNotNull.test.ts +7 -7
- package/tests/cases/integration/graphQlDb/update/nullChecksNullable.test.ts +7 -7
- package/tests/cases/integration/graphQlDb/update/uniqueConstraint.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/insert/oneHasMany/connect.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.ts +67 -0
- package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +6 -18
- package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +3 -4
- package/tests/cases/integration/graphQlRequests/update/basic/columnUpdate.test.ts +3 -8
- package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/update.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/upsert.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/update.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/upsert.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasOne/connect.test.ts +3 -10
- package/tests/cases/integration/graphQlRequests/update/manyHasOne/create.test.ts +3 -10
- package/tests/cases/integration/graphQlRequests/update/manyHasOne/disconnect.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasOne/update.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/manyHasOne/upsert.test.ts +6 -18
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/connect.test.ts +3 -11
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/disconnect.test.ts +3 -8
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/update.test.ts +3 -6
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/upsert.test.ts +3 -6
- package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/connect.test.ts +15 -50
- package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/create.test.ts +3 -10
- package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/disconnect.test.ts +3 -10
- package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/update.test.ts +3 -6
- package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/upsert.test.ts +3 -7
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connect.test.ts +12 -32
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connectOrCreate.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/create.test.ts +6 -20
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/disconnect.test.ts +3 -10
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/update.test.ts +3 -9
- package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/upsert.test.ts +6 -19
- package/tests/cases/integration/graphQlRequests/update/queryPortal.test.ts +6 -8
- package/tests/cases/integration/graphQlRequests/update/transaction.test.ts +9 -24
- package/tests/cases/integration/graphQlRequests/upsert/basicUpsert.test.ts +3 -7
- package/tests/cases/unit/orderbyHelper.test.ts +13 -0
- package/tests/src/test.ts +38 -15
- package/tests/tsconfig.json +3 -9
- package/dist/src/mapper/MapperContainer.d.ts +0 -18
- package/dist/src/mapper/MapperContainer.d.ts.map +0 -1
- package/dist/src/mapper/MapperContainer.js +0 -55
- package/dist/src/mapper/MapperContainer.js.map +0 -1
- package/dist/src/resolvers/ExecutionContainerFactory.d.ts +0 -24
- package/dist/src/resolvers/ExecutionContainerFactory.d.ts.map +0 -1
- package/dist/src/resolvers/ExecutionContainerFactory.js +0 -45
- package/dist/src/resolvers/ExecutionContainerFactory.js.map +0 -1
- package/src/mapper/MapperContainer.ts +0 -142
- package/src/resolvers/ExecutionContainerFactory.ts +0 -74
|
@@ -2,13 +2,11 @@ import { Input, Model } from '@contember/schema'
|
|
|
2
2
|
import { MapperFactory } from '../mapper'
|
|
3
3
|
import { GraphQLResolveInfo } from 'graphql'
|
|
4
4
|
import { GraphQlQueryAstFactory } from './GraphQlQueryAstFactory'
|
|
5
|
-
import { Client, Connection } from '@contember/database'
|
|
6
5
|
import { ObjectNode } from '../inputProcessing'
|
|
7
6
|
import { executeReadOperations, paginate } from './ReadHelpers'
|
|
8
7
|
|
|
9
8
|
export class ReadResolver {
|
|
10
9
|
constructor(
|
|
11
|
-
private readonly db: Client,
|
|
12
10
|
private readonly mapperFactory: MapperFactory,
|
|
13
11
|
private readonly queryAstFactory: GraphQlQueryAstFactory,
|
|
14
12
|
) {}
|
|
@@ -16,7 +14,7 @@ export class ReadResolver {
|
|
|
16
14
|
public async resolveQuery(info: GraphQLResolveInfo) {
|
|
17
15
|
const queryAst = this.queryAstFactory.create(info)
|
|
18
16
|
const fields = GraphQlQueryAstFactory.resolveObjectType(info.returnType).getFields()
|
|
19
|
-
const mapper = this.mapperFactory(
|
|
17
|
+
const mapper = this.mapperFactory.create()
|
|
20
18
|
return executeReadOperations(queryAst, fields, mapper)
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -24,26 +22,24 @@ export class ReadResolver {
|
|
|
24
22
|
const queryAst = this.queryAstFactory.create(info)
|
|
25
23
|
const fields = GraphQlQueryAstFactory.resolveObjectType(info.returnType).getFields()
|
|
26
24
|
|
|
27
|
-
return this.
|
|
28
|
-
await trx.connection.query(Connection.REPEATABLE_READ)
|
|
29
|
-
const mapper = this.mapperFactory(trx)
|
|
25
|
+
return this.mapperFactory.transaction(async mapper => {
|
|
30
26
|
return executeReadOperations(queryAst, fields, mapper)
|
|
31
27
|
})
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
public async resolveListQuery(entity: Model.Entity, info: GraphQLResolveInfo) {
|
|
35
31
|
const queryAst: ObjectNode<Input.ListQueryInput> = this.queryAstFactory.create(info)
|
|
36
|
-
return await this.mapperFactory(
|
|
32
|
+
return await this.mapperFactory.create().select(entity, queryAst, [])
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
public async resolveGetQuery(entity: Model.Entity, info: GraphQLResolveInfo) {
|
|
40
36
|
const queryAst: ObjectNode<Input.UniqueQueryInput> = this.queryAstFactory.create(info)
|
|
41
|
-
return await this.mapperFactory(
|
|
37
|
+
return await this.mapperFactory.create().selectUnique(entity, queryAst, [])
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
public async resolvePaginationQuery(entity: Model.Entity, info: GraphQLResolveInfo) {
|
|
45
41
|
const queryAst: ObjectNode<Input.PaginationQueryInput> = this.queryAstFactory.create(info)
|
|
46
|
-
const mapper = this.mapperFactory(
|
|
42
|
+
const mapper = this.mapperFactory.create()
|
|
47
43
|
return await paginate(mapper, entity, queryAst)
|
|
48
44
|
}
|
|
49
45
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Input, Model, Result } from '@contember/schema'
|
|
2
2
|
import { assertNever } from '../utils'
|
|
3
3
|
import { InputPreValidator, ValidationResult } from '../input-validation'
|
|
4
|
-
import { Client } from '@contember/database'
|
|
5
4
|
import { MapperFactory } from '../mapper'
|
|
6
5
|
|
|
7
6
|
export class ValidationResolver {
|
|
8
7
|
constructor(
|
|
9
|
-
private readonly db: Client,
|
|
10
8
|
private readonly mapperFactory: MapperFactory,
|
|
11
9
|
private readonly inputValidator: InputPreValidator,
|
|
12
10
|
) {}
|
|
13
11
|
|
|
14
12
|
public async validateUpdate(entity: Model.Entity, input: Input.UpdateInput): Promise<Result.ValidationResult> {
|
|
15
|
-
const mapper = this.mapperFactory(
|
|
13
|
+
const mapper = this.mapperFactory.create()
|
|
16
14
|
const validationResult = await this.inputValidator.validateUpdate({
|
|
17
15
|
mapper,
|
|
18
16
|
entity,
|
|
@@ -31,7 +29,7 @@ export class ValidationResolver {
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
public async validateCreate(entity: Model.Entity, input: Input.CreateInput): Promise<Result.ValidationResult> {
|
|
34
|
-
const mapper = this.mapperFactory(
|
|
32
|
+
const mapper = this.mapperFactory.create()
|
|
35
33
|
const validationResult = await this.inputValidator.validateCreate({
|
|
36
34
|
mapper,
|
|
37
35
|
entity,
|
package/src/resolvers/index.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import { GraphQLScalarType, Kind } from 'graphql'
|
|
2
|
-
import { JSONType } from '@contember/graphql-utils'
|
|
2
|
+
import { JSONType, UuidType } from '@contember/graphql-utils'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const uuidPattern = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i
|
|
6
|
-
/** dashes are optional */
|
|
7
|
-
const isUuid = (value: string): boolean => {
|
|
8
|
-
return (
|
|
9
|
-
value.length <= 36 &&
|
|
10
|
-
value.length >= 32 &&
|
|
11
|
-
value.match(uuidPattern) !== null
|
|
12
|
-
)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
5
|
export class CustomTypesProvider {
|
|
16
|
-
public readonly uuidType: GraphQLScalarType =
|
|
17
|
-
name: 'UUID',
|
|
18
|
-
serialize: str => String(str),
|
|
19
|
-
parseValue: str => {
|
|
20
|
-
if (typeof str !== 'string' || !isUuid(str)) {
|
|
21
|
-
return undefined
|
|
22
|
-
}
|
|
23
|
-
return str
|
|
24
|
-
},
|
|
25
|
-
parseLiteral: function parseLiteral(ast) {
|
|
26
|
-
if (ast.kind !== Kind.STRING || !isUuid(ast.value)) {
|
|
27
|
-
return undefined
|
|
28
|
-
}
|
|
29
|
-
return ast.value
|
|
30
|
-
},
|
|
31
|
-
})
|
|
6
|
+
public readonly uuidType: GraphQLScalarType = UuidType
|
|
32
7
|
|
|
33
8
|
//todo: implement serialize, parseValue and parseLiteral properly
|
|
34
9
|
public readonly dateType: GraphQLScalarType = new GraphQLScalarType({
|
|
@@ -58,7 +58,7 @@ export class MutationProvider {
|
|
|
58
58
|
if (parent && info.path) {
|
|
59
59
|
return parent[info.path.key]
|
|
60
60
|
}
|
|
61
|
-
return context.executionContainer.
|
|
61
|
+
return context.executionContainer.mutationResolver.resolveCreate(entity, info)
|
|
62
62
|
})
|
|
63
63
|
},
|
|
64
64
|
}
|
|
@@ -92,7 +92,7 @@ export class MutationProvider {
|
|
|
92
92
|
if (parent && info.path) {
|
|
93
93
|
return parent[info.path.key]
|
|
94
94
|
}
|
|
95
|
-
return context.executionContainer.
|
|
95
|
+
return context.executionContainer.mutationResolver.resolveDelete(entity, info)
|
|
96
96
|
})
|
|
97
97
|
},
|
|
98
98
|
}
|
|
@@ -126,7 +126,7 @@ export class MutationProvider {
|
|
|
126
126
|
if (parent && info.path) {
|
|
127
127
|
return parent[info.path.key]
|
|
128
128
|
}
|
|
129
|
-
return context.executionContainer.
|
|
129
|
+
return context.executionContainer.mutationResolver.resolveUpdate(entity, info)
|
|
130
130
|
})
|
|
131
131
|
},
|
|
132
132
|
}
|
|
@@ -165,7 +165,7 @@ export class MutationProvider {
|
|
|
165
165
|
if (parent && info.path) {
|
|
166
166
|
return parent[info.path.key]
|
|
167
167
|
}
|
|
168
|
-
return context.executionContainer.
|
|
168
|
+
return context.executionContainer.mutationResolver.resolveUpsert(entity, info)
|
|
169
169
|
})
|
|
170
170
|
},
|
|
171
171
|
}
|
|
@@ -52,7 +52,7 @@ export class QueryProvider {
|
|
|
52
52
|
if (parent && info.path) {
|
|
53
53
|
return parent[info.path.key]
|
|
54
54
|
}
|
|
55
|
-
return context.executionContainer.
|
|
55
|
+
return context.executionContainer.readResolver.resolveGetQuery(entity, info)
|
|
56
56
|
})
|
|
57
57
|
},
|
|
58
58
|
}
|
|
@@ -84,7 +84,7 @@ export class QueryProvider {
|
|
|
84
84
|
if (parent && info.path) {
|
|
85
85
|
return parent[info.path.key]
|
|
86
86
|
}
|
|
87
|
-
return context.executionContainer.
|
|
87
|
+
return context.executionContainer.readResolver.resolveListQuery(entity, info)
|
|
88
88
|
})
|
|
89
89
|
},
|
|
90
90
|
}
|
|
@@ -99,7 +99,7 @@ export class QueryProvider {
|
|
|
99
99
|
if (parent && info.path) {
|
|
100
100
|
return parent[info.path.key]
|
|
101
101
|
}
|
|
102
|
-
return context.executionContainer.
|
|
102
|
+
return context.executionContainer.readResolver.resolvePaginationQuery(entity, info)
|
|
103
103
|
})
|
|
104
104
|
},
|
|
105
105
|
}
|
package/src/tsconfig.json
CHANGED
|
@@ -5,26 +5,12 @@
|
|
|
5
5
|
"esModuleInterop": true
|
|
6
6
|
},
|
|
7
7
|
"references": [
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"path": "../../graphql-utils/src"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"path": "../../logger/src"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"path": "../../schema/src"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"path": "../../schema-definition/src"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"path": "../../schema-utils/src"
|
|
28
|
-
}
|
|
8
|
+
{ "path": "../../database/src" },
|
|
9
|
+
{ "path": "../../dic/src" },
|
|
10
|
+
{ "path": "../../graphql-utils/src" },
|
|
11
|
+
{ "path": "../../logger/src" },
|
|
12
|
+
{ "path": "../../schema/src" },
|
|
13
|
+
{ "path": "../../schema-definition/src" },
|
|
14
|
+
{ "path": "../../schema-utils/src" }
|
|
29
15
|
]
|
|
30
16
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Acl } from '@contember/schema'
|
|
2
2
|
import { Client } from '@contember/database'
|
|
3
|
-
import {
|
|
4
|
-
import { ExecutionContainer } from './resolvers'
|
|
3
|
+
import { ExecutionContainer } from './ExecutionContainer'
|
|
5
4
|
|
|
6
5
|
export interface Context {
|
|
7
6
|
db: Client
|
|
8
7
|
identityVariables: Acl.VariablesMap
|
|
9
|
-
executionContainer:
|
|
8
|
+
executionContainer: ExecutionContainer
|
|
10
9
|
timer: <T>(event: string, cb?: () => T) => Promise<T>
|
|
11
10
|
}
|
|
@@ -31,11 +31,9 @@ test('Update by nested unique where', async () => {
|
|
|
31
31
|
parameters: ['en'],
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
sql: SQL`
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
update "public"."front_page" set "title" = "newData_"."title" from "newData_" where "front_page"."id" = "newData_"."id"`,
|
|
38
|
-
response: { rowCount: 1 },
|
|
34
|
+
sql: SQL`with "newData_" as (select ? :: text as "title", "root_"."title" as "title_old__", "root_"."id", "root_"."site_id" from "public"."front_page" as "root_" where "root_"."id" = ?)
|
|
35
|
+
update "public"."front_page" set "title" = "newData_"."title" from "newData_" where "front_page"."id" = "newData_"."id" returning "title_old__"`,
|
|
36
|
+
response: { rows: [{}] },
|
|
39
37
|
parameters: ['Hello', testUuid(1)],
|
|
40
38
|
},
|
|
41
39
|
]),
|
|
@@ -10,9 +10,9 @@ namespace SeqModel {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
test('insert author with id', async () => {
|
|
13
|
-
const
|
|
13
|
+
const model = def.createModel(SeqModel)
|
|
14
14
|
await executeDbTest({
|
|
15
|
-
schema:
|
|
15
|
+
schema: { model },
|
|
16
16
|
query: GQL`
|
|
17
17
|
mutation {
|
|
18
18
|
createOrder(data: {}) {
|
|
@@ -6,7 +6,7 @@ import { executeDbTest } from '@contember/engine-api-tester'
|
|
|
6
6
|
|
|
7
7
|
test('delete without deferring constraints', async () => {
|
|
8
8
|
await executeDbTest({
|
|
9
|
-
schema: new SchemaBuilder()
|
|
9
|
+
schema: { model: new SchemaBuilder()
|
|
10
10
|
.entity('Post', entity =>
|
|
11
11
|
entity
|
|
12
12
|
.column('slug')
|
|
@@ -25,7 +25,7 @@ test('delete without deferring constraints', async () => {
|
|
|
25
25
|
.manyHasOne('attachment', relation => relation.target('Attachment').inversedBy('refereces'))
|
|
26
26
|
.unique(['slug']),
|
|
27
27
|
)
|
|
28
|
-
.buildSchema(),
|
|
28
|
+
.buildSchema() },
|
|
29
29
|
seed: [
|
|
30
30
|
{
|
|
31
31
|
query: `mutation {
|
|
@@ -60,10 +60,10 @@ test('delete without deferring constraints', async () => {
|
|
|
60
60
|
return: {
|
|
61
61
|
transaction: {
|
|
62
62
|
ok: false,
|
|
63
|
-
errorMessage: 'Execution has failed:\nupdatePost.attachments.0: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-
|
|
63
|
+
errorMessage: 'Execution has failed:\nupdatePost.attachments.0: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-000000000004 row(s) of entity Attachment, because it is still referenced from 123e4567-e89b-12d3-a456-000000000006 row(s) of entity Reference in relation attachment. OnDelete behaviour of this relation is set to "restrict". You might consider changing it to "setNull" or "cascade".)',
|
|
64
64
|
updatePost: {
|
|
65
65
|
ok: false,
|
|
66
|
-
errorMessage: 'Execution has failed:\nattachments.0: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-
|
|
66
|
+
errorMessage: 'Execution has failed:\nattachments.0: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-000000000004 row(s) of entity Attachment, because it is still referenced from 123e4567-e89b-12d3-a456-000000000006 row(s) of entity Reference in relation attachment. OnDelete behaviour of this relation is set to "restrict". You might consider changing it to "setNull" or "cascade".)',
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
69
|
},
|
|
@@ -73,7 +73,7 @@ test('delete without deferring constraints', async () => {
|
|
|
73
73
|
|
|
74
74
|
test('delete with successfully deferring constraints', async () => {
|
|
75
75
|
await executeDbTest({
|
|
76
|
-
schema: new SchemaBuilder()
|
|
76
|
+
schema: { model: new SchemaBuilder()
|
|
77
77
|
.entity('Post', entity =>
|
|
78
78
|
entity
|
|
79
79
|
.column('slug')
|
|
@@ -92,7 +92,7 @@ test('delete with successfully deferring constraints', async () => {
|
|
|
92
92
|
.manyHasOne('attachment', relation => relation.target('Attachment').inversedBy('refereces'))
|
|
93
93
|
.unique(['slug']),
|
|
94
94
|
)
|
|
95
|
-
.buildSchema(),
|
|
95
|
+
.buildSchema() },
|
|
96
96
|
seed: [
|
|
97
97
|
{
|
|
98
98
|
query: `mutation {
|
|
@@ -140,7 +140,7 @@ test('delete with successfully deferring constraints', async () => {
|
|
|
140
140
|
|
|
141
141
|
test('delete with unsuccessfully deferring constraints', async () => {
|
|
142
142
|
await executeDbTest({
|
|
143
|
-
schema: new SchemaBuilder()
|
|
143
|
+
schema: { model: new SchemaBuilder()
|
|
144
144
|
.entity('Post', entity =>
|
|
145
145
|
entity
|
|
146
146
|
.column('slug')
|
|
@@ -159,7 +159,7 @@ test('delete with unsuccessfully deferring constraints', async () => {
|
|
|
159
159
|
.manyHasOne('attachment', relation => relation.target('Attachment').inversedBy('refereces'))
|
|
160
160
|
.unique(['slug']),
|
|
161
161
|
)
|
|
162
|
-
.buildSchema(),
|
|
162
|
+
.buildSchema() },
|
|
163
163
|
seed: [
|
|
164
164
|
{
|
|
165
165
|
query: `mutation {
|
|
@@ -194,7 +194,7 @@ test('delete with unsuccessfully deferring constraints', async () => {
|
|
|
194
194
|
return: {
|
|
195
195
|
transaction: {
|
|
196
196
|
ok: false,
|
|
197
|
-
errorMessage: 'Execution has failed:\nunknown field: ForeignKeyConstraintViolation (Cannot delete row 123e4567-e89b-12d3-a456-
|
|
197
|
+
errorMessage: 'Execution has failed:\nunknown field: ForeignKeyConstraintViolation (Cannot delete row 123e4567-e89b-12d3-a456-000000000004 of entity Attachment, because it is still referenced from Reference::attachment. This is possibly caused by ACL denial or by missing "on delete cascade")',
|
|
198
198
|
updatePost: {
|
|
199
199
|
ok: false,
|
|
200
200
|
errorMessage: null,
|
|
@@ -6,14 +6,14 @@ import { executeDbTest } from '@contember/engine-api-tester'
|
|
|
6
6
|
|
|
7
7
|
test('fails when deleting entity without proper cascade', async () => {
|
|
8
8
|
await executeDbTest({
|
|
9
|
-
schema: new SchemaBuilder()
|
|
9
|
+
schema: { model: new SchemaBuilder()
|
|
10
10
|
.entity('Post', entity =>
|
|
11
11
|
entity.column('slug').unique(['slug']),
|
|
12
12
|
)
|
|
13
13
|
.entity('PostLocales', entity =>
|
|
14
14
|
entity.manyHasOne('post', relation => relation.target('Post').inversedBy('locales')).column('title'),
|
|
15
15
|
)
|
|
16
|
-
.buildSchema(),
|
|
16
|
+
.buildSchema() },
|
|
17
17
|
seed: [
|
|
18
18
|
{
|
|
19
19
|
query: `mutation {
|
|
@@ -37,7 +37,7 @@ test('fails when deleting entity without proper cascade', async () => {
|
|
|
37
37
|
}`,
|
|
38
38
|
return: {
|
|
39
39
|
deletePost: {
|
|
40
|
-
errorMessage: 'Execution has failed:\nunknown field: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-
|
|
40
|
+
errorMessage: 'Execution has failed:\nunknown field: ForeignKeyConstraintViolation (Cannot delete 123e4567-e89b-12d3-a456-000000000003 row(s) of entity Post, because it is still referenced from 123e4567-e89b-12d3-a456-000000000004 row(s) of entity PostLocales in relation post. OnDelete behaviour of this relation is set to "restrict". You might consider changing it to "setNull" or "cascade".)',
|
|
41
41
|
node: null,
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -4,7 +4,7 @@ import { test, assert } from 'vitest'
|
|
|
4
4
|
import { executeDbTest } from '@contember/engine-api-tester'
|
|
5
5
|
import { GQL } from '../../../../src/tags'
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const model = new SchemaBuilder()
|
|
8
8
|
.entity('Post', e =>
|
|
9
9
|
e
|
|
10
10
|
.column('slug', c => c.type(Model.ColumnType.String).unique())
|
|
@@ -13,7 +13,7 @@ const schema = new SchemaBuilder()
|
|
|
13
13
|
.buildSchema()
|
|
14
14
|
test('returns error for invalid date input', async () => {
|
|
15
15
|
await executeDbTest({
|
|
16
|
-
schema,
|
|
16
|
+
schema: { model },
|
|
17
17
|
seed: [
|
|
18
18
|
{
|
|
19
19
|
query: GQL`mutation {
|
|
@@ -5,7 +5,7 @@ import { executeDbTest } from '@contember/engine-api-tester'
|
|
|
5
5
|
import { GQL } from '../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../src/testUuid'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const model = new SchemaBuilder()
|
|
9
9
|
.entity('Site', e =>
|
|
10
10
|
e
|
|
11
11
|
.column('slug', c => c.unique().type(Model.ColumnType.String))
|
|
@@ -17,7 +17,7 @@ const schema = new SchemaBuilder()
|
|
|
17
17
|
|
|
18
18
|
test('update site & create contact page', async () => {
|
|
19
19
|
await executeDbTest({
|
|
20
|
-
schema,
|
|
20
|
+
schema: { model },
|
|
21
21
|
seed: [
|
|
22
22
|
{
|
|
23
23
|
query: GQL`mutation {
|
|
@@ -38,15 +38,15 @@ test('update site & create contact page', async () => {
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
expectDatabase: {
|
|
41
|
-
site: [{ id: testUuid(
|
|
42
|
-
contact_page: [{ id: testUuid(
|
|
41
|
+
site: [{ id: testUuid(3), slug: 'en', contact_page_id: testUuid(5) }],
|
|
42
|
+
contact_page: [{ id: testUuid(5), title: 'Test' }],
|
|
43
43
|
},
|
|
44
44
|
})
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
test('update site & try to create contact page which however exists', async () => {
|
|
48
48
|
await executeDbTest({
|
|
49
|
-
schema,
|
|
49
|
+
schema: { model },
|
|
50
50
|
seed: [
|
|
51
51
|
{
|
|
52
52
|
query: GQL`mutation {
|
|
@@ -75,8 +75,8 @@ test('update site & try to create contact page which however exists', async () =
|
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
expectDatabase: {
|
|
78
|
-
site: [{ id: testUuid(
|
|
79
|
-
contact_page: [{ id: testUuid(
|
|
78
|
+
site: [{ id: testUuid(3), slug: 'en', contact_page_id: testUuid(4) }],
|
|
79
|
+
contact_page: [{ id: testUuid(4), title: 'Test' }],
|
|
80
80
|
},
|
|
81
81
|
})
|
|
82
82
|
})
|
|
@@ -5,7 +5,7 @@ import { executeDbTest } from '@contember/engine-api-tester'
|
|
|
5
5
|
import { GQL } from '../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../src/testUuid'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const model = new SchemaBuilder()
|
|
9
9
|
.entity('Site', e => e.column('slug', c => c.unique().type(Model.ColumnType.String)))
|
|
10
10
|
.entity('ContactPage', e =>
|
|
11
11
|
e.column('title').oneHasOne('site', r => r.target('Site').inversedBy('contactPage').notNull()),
|
|
@@ -14,7 +14,7 @@ const schema = new SchemaBuilder()
|
|
|
14
14
|
|
|
15
15
|
test('update site & create contact page', async () => {
|
|
16
16
|
await executeDbTest({
|
|
17
|
-
schema,
|
|
17
|
+
schema: { model },
|
|
18
18
|
seed: [
|
|
19
19
|
{
|
|
20
20
|
query: GQL`mutation {
|
|
@@ -35,15 +35,15 @@ test('update site & create contact page', async () => {
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
expectDatabase: {
|
|
38
|
-
site: [{ id: testUuid(
|
|
39
|
-
contact_page: [{ site_id: testUuid(
|
|
38
|
+
site: [{ id: testUuid(3), slug: 'en' }],
|
|
39
|
+
contact_page: [{ site_id: testUuid(3), id: testUuid(5), title: 'Test' }],
|
|
40
40
|
},
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
test('update site & try to create contact page which however exists', async () => {
|
|
45
45
|
await executeDbTest({
|
|
46
|
-
schema,
|
|
46
|
+
schema: { model },
|
|
47
47
|
seed: [
|
|
48
48
|
{
|
|
49
49
|
query: GQL`mutation {
|
|
@@ -72,8 +72,8 @@ test('update site & try to create contact page which however exists', async () =
|
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
expectDatabase: {
|
|
75
|
-
site: [{ id: testUuid(
|
|
76
|
-
contact_page: [{ site_id: testUuid(
|
|
75
|
+
site: [{ id: testUuid(3), slug: 'en' }],
|
|
76
|
+
contact_page: [{ site_id: testUuid(3), id: testUuid(4), title: 'Test' }],
|
|
77
77
|
},
|
|
78
78
|
})
|
|
79
79
|
})
|
|
@@ -4,7 +4,7 @@ import { test } from 'vitest'
|
|
|
4
4
|
import { executeDbTest } from '@contember/engine-api-tester'
|
|
5
5
|
import { GQL } from '../../../../src/tags'
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const model = new SchemaBuilder()
|
|
8
8
|
.entity('Site', e =>
|
|
9
9
|
e.column('slug', c => c.unique().type(Model.ColumnType.String)),
|
|
10
10
|
)
|
|
@@ -12,7 +12,7 @@ const schema = new SchemaBuilder()
|
|
|
12
12
|
|
|
13
13
|
test('fail when creating a non-unique site', async () => {
|
|
14
14
|
await executeDbTest({
|
|
15
|
-
schema,
|
|
15
|
+
schema: { model },
|
|
16
16
|
seed: [
|
|
17
17
|
{
|
|
18
18
|
query: GQL`mutation {
|
|
@@ -41,11 +41,11 @@ test('insert category and connect existing post (one has many)', async () => {
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
|
-
sql: SQL`with "
|
|
45
|
-
|
|
44
|
+
sql: SQL`with "newData_" as (select ? :: uuid as "category_id", "root_"."category_id" as "category_id_old__", "root_"."id", "root_"."name" from "public"."post" as "root_" where "root_"."id" = ?)
|
|
45
|
+
update "public"."post" set "category_id" = "newData_"."category_id" from "newData_" where "post"."id" = "newData_"."id" returning "category_id_old__"`,
|
|
46
46
|
parameters: [testUuid(1), testUuid(5)],
|
|
47
47
|
response: {
|
|
48
|
-
|
|
48
|
+
rows: [{ category_id_old__: testUuid(99) }],
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { test } from 'vitest'
|
|
2
|
+
import { execute } from '../../../../../src/test'
|
|
3
|
+
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
+
import { Model } from '@contember/schema'
|
|
5
|
+
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
|
+
import { testUuid } from '../../../../../src/testUuid'
|
|
7
|
+
|
|
8
|
+
test('Entity - explicit order by, default asc', async () => {
|
|
9
|
+
await execute({
|
|
10
|
+
schema: new SchemaBuilder()
|
|
11
|
+
.entity('Post', entity => entity.column('title', column => column.type(Model.ColumnType.String)).orderBy('title'))
|
|
12
|
+
.buildSchema(),
|
|
13
|
+
query: GQL`
|
|
14
|
+
query {
|
|
15
|
+
getPost(by: {id: "${testUuid(1)}"}, filter: {title: {eq: "Foo"}}) {
|
|
16
|
+
id
|
|
17
|
+
}
|
|
18
|
+
}`,
|
|
19
|
+
executes: [
|
|
20
|
+
{
|
|
21
|
+
sql: SQL`select "root_"."id" as "root_id"
|
|
22
|
+
from "public"."post" as "root_"
|
|
23
|
+
where "root_"."id" = ? and "root_"."title" = ? order by "root_"."title" asc, "root_"."id" asc`,
|
|
24
|
+
response: { rows: [{ root_id: testUuid(1) }] },
|
|
25
|
+
parameters: [testUuid(1), 'Foo'],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
return: {
|
|
29
|
+
data: {
|
|
30
|
+
getPost: {
|
|
31
|
+
id: testUuid(1),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
test('Entity - explicit order by desc', async () => {
|
|
40
|
+
await execute({
|
|
41
|
+
schema: new SchemaBuilder()
|
|
42
|
+
.entity('Post', entity => entity.column('title', column => column.type(Model.ColumnType.String)).orderBy('title', Model.OrderDirection.desc))
|
|
43
|
+
.buildSchema(),
|
|
44
|
+
query: GQL`
|
|
45
|
+
query {
|
|
46
|
+
getPost(by: {id: "${testUuid(1)}"}, filter: {title: {eq: "Foo"}}) {
|
|
47
|
+
id
|
|
48
|
+
}
|
|
49
|
+
}`,
|
|
50
|
+
executes: [
|
|
51
|
+
{
|
|
52
|
+
sql: SQL`select "root_"."id" as "root_id"
|
|
53
|
+
from "public"."post" as "root_"
|
|
54
|
+
where "root_"."id" = ? and "root_"."title" = ? order by "root_"."title" desc, "root_"."id" asc`,
|
|
55
|
+
response: { rows: [{ root_id: testUuid(1) }] },
|
|
56
|
+
parameters: [testUuid(1), 'Foo'],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
return: {
|
|
60
|
+
data: {
|
|
61
|
+
getPost: {
|
|
62
|
+
id: testUuid(1),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -45,16 +45,10 @@ test('update name', async () => {
|
|
|
45
45
|
response: { rows: [{ id: testUuid(1) }] },
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
sql: SQL`with "newData_" as
|
|
49
|
-
|
|
50
|
-
? :: text as "name",
|
|
51
|
-
"root_"."id"
|
|
52
|
-
from "public"."author" as "root_"
|
|
53
|
-
where "root_"."id" = ? and "root_"."name" in (?, ?)) update "public"."author"
|
|
54
|
-
set "name" = "newData_"."name" from "newData_"
|
|
55
|
-
where "author"."id" = "newData_"."id" and "newData_"."name" in (?, ?)`,
|
|
48
|
+
sql: SQL`with "newData_" as (select ? :: text as "name", "root_"."name" as "name_old__", "root_"."id" from "public"."author" as "root_" where "root_"."id" = ? and "root_"."name" in (?, ?))
|
|
49
|
+
update "public"."author" set "name" = "newData_"."name" from "newData_" where "author"."id" = "newData_"."id" and "newData_"."name" in (?, ?) returning "name_old__"`,
|
|
56
50
|
parameters: ['John', testUuid(1), 'John', 'Jack', 'John', 'Jack'],
|
|
57
|
-
response: {
|
|
51
|
+
response: { rows: [{ name_old__: 'John' }] },
|
|
58
52
|
},
|
|
59
53
|
]),
|
|
60
54
|
],
|
|
@@ -108,16 +102,10 @@ test('update name - denied', async () => {
|
|
|
108
102
|
response: { rows: [{ id: testUuid(1) }] },
|
|
109
103
|
},
|
|
110
104
|
{
|
|
111
|
-
sql: SQL`with "newData_" as
|
|
112
|
-
|
|
113
|
-
? :: text as "name",
|
|
114
|
-
"root_"."id"
|
|
115
|
-
from "public"."author" as "root_"
|
|
116
|
-
where false) update "public"."author"
|
|
117
|
-
set "name" = "newData_"."name" from "newData_"
|
|
118
|
-
where "author"."id" = "newData_"."id" and false`,
|
|
105
|
+
sql: SQL`with "newData_" as (select ? :: text as "name", "root_"."name" as "name_old__", "root_"."id" from "public"."author" as "root_" where false)
|
|
106
|
+
update "public"."author" set "name" = "newData_"."name" from "newData_" where "author"."id" = "newData_"."id" and false returning "name_old__"`,
|
|
119
107
|
parameters: ['John'],
|
|
120
|
-
response:
|
|
108
|
+
response: { rows: [] },
|
|
121
109
|
},
|
|
122
110
|
]),
|
|
123
111
|
],
|