@contember/engine-content-api 1.3.0-alpha.1 → 1.3.0-alpha.13
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 +144 -0
- package/dist/src/ExecutionContainer.d.ts.map +1 -0
- package/dist/src/ExecutionContainer.js +85 -0
- package/dist/src/ExecutionContainer.js.map +1 -0
- package/dist/src/acl/PermissionFactory.d.ts +5 -4
- package/dist/src/acl/PermissionFactory.d.ts.map +1 -1
- package/dist/src/acl/PermissionFactory.js +10 -13
- package/dist/src/acl/PermissionFactory.js.map +1 -1
- package/dist/src/acl/index.d.ts +0 -1
- package/dist/src/acl/index.d.ts.map +1 -1
- package/dist/src/acl/index.js +0 -1
- package/dist/src/acl/index.js.map +1 -1
- 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/ErrorUtils.d.ts +3 -2
- package/dist/src/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/src/mapper/ErrorUtils.js +55 -35
- package/dist/src/mapper/ErrorUtils.js.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 +13 -6
- package/dist/src/mapper/Mapper.d.ts.map +1 -1
- package/dist/src/mapper/Mapper.js +41 -21
- package/dist/src/mapper/Mapper.js.map +1 -1
- package/dist/src/mapper/MapperFactory.d.ts +34 -0
- package/dist/src/mapper/MapperFactory.d.ts.map +1 -0
- package/dist/src/mapper/MapperFactory.js +41 -0
- package/dist/src/mapper/MapperFactory.js.map +1 -0
- package/dist/src/mapper/Result.d.ts +5 -3
- package/dist/src/mapper/Result.d.ts.map +1 -1
- package/dist/src/mapper/Result.js +4 -3
- 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.d.ts +3 -2
- package/dist/src/mapper/insert/Inserter.d.ts.map +1 -1
- package/dist/src/mapper/insert/Inserter.js +7 -6
- 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 +3 -1
- package/dist/src/mapper/update/Updater.d.ts.map +1 -1
- package/dist/src/mapper/update/Updater.js +9 -12
- 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 +3 -4
- package/dist/src/resolvers/MutationResolver.d.ts.map +1 -1
- package/dist/src/resolvers/MutationResolver.js +11 -12
- 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 +3 -4
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +0 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/uniqueWhereFields.js +1 -1
- package/dist/src/utils/uniqueWhereFields.js.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/acl/isNullAcl.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/isNullAcl.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/isNullAcl.test.js +91 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/isNullAcl.test.js.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.js +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.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 +13 -2
- package/dist/tests/cases/unit/orderbyHelper.test.js.map +1 -1
- package/dist/tests/cases/unit/permissionMerger.test.js +8 -3
- package/dist/tests/cases/unit/permissionMerger.test.js.map +1 -1
- package/dist/tests/cases/unit/predicatesInjector.test.js +1 -1
- package/dist/tests/cases/unit/predicatesInjector.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 +35 -6
- package/dist/tests/src/test.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -13
- package/src/ExecutionContainer.ts +208 -0
- package/src/acl/PermissionFactory.ts +15 -13
- package/src/acl/index.ts +0 -1
- package/src/index.ts +24 -1
- package/src/mapper/ColumnValue.ts +2 -2
- package/src/mapper/ErrorUtils.ts +66 -41
- package/src/mapper/EventManager.ts +158 -0
- package/src/mapper/JunctionTableManager.ts +50 -32
- package/src/mapper/Mapper.ts +48 -27
- package/src/mapper/MapperFactory.ts +69 -0
- package/src/mapper/Result.ts +5 -2
- 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 +7 -7
- 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 +9 -13
- package/src/resolvers/GraphQlQueryAstFactory.ts +1 -2
- package/src/resolvers/MutationResolver.ts +15 -14
- 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 +3 -4
- package/src/utils/index.ts +0 -1
- package/src/utils/uniqueWhereFields.ts +1 -1
- 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/acl/isNullAcl.test.ts +77 -0
- package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +1 -1
- 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 +15 -2
- package/tests/cases/unit/permissionMerger.test.ts +9 -4
- package/tests/cases/unit/predicatesInjector.test.ts +1 -1
- package/tests/src/test.ts +40 -16
- package/tests/tsconfig.json +3 -9
- package/dist/src/acl/PermissionsByIdentityFactory.d.ts +0 -12
- package/dist/src/acl/PermissionsByIdentityFactory.d.ts.map +0 -1
- package/dist/src/acl/PermissionsByIdentityFactory.js +0 -15
- package/dist/src/acl/PermissionsByIdentityFactory.js.map +0 -1
- 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/dist/src/utils/arrays.d.ts +0 -3
- package/dist/src/utils/arrays.d.ts.map +0 -1
- package/dist/src/utils/arrays.js +0 -22
- package/dist/src/utils/arrays.js.map +0 -1
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +0 -420
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +0 -229
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-predicate.gql +0 -112
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-predicate2.gql +0 -112
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +0 -309
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +0 -402
- package/dist/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +0 -338
- package/dist/tests/cases/integration/graphQlSchema/schema-acl.gql +0 -221
- package/dist/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +0 -226
- package/dist/tests/cases/integration/graphQlSchema/schema-basic.gql +0 -841
- package/dist/tests/cases/integration/graphQlSchema/schema-bug-66.gql +0 -540
- package/dist/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +0 -851
- package/dist/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +0 -453
- package/dist/tests/cases/integration/graphQlSchema/schema-new-builder.gql +0 -912
- package/dist/tests/cases/integration/graphQlSchema/schema-view-entity.gql +0 -112
- package/src/acl/PermissionsByIdentityFactory.ts +0 -21
- package/src/mapper/MapperContainer.ts +0 -142
- package/src/resolvers/ExecutionContainerFactory.ts +0 -74
- package/src/utils/arrays.ts +0 -19
package/src/mapper/index.ts
CHANGED
|
@@ -5,9 +5,11 @@ export * from './update'
|
|
|
5
5
|
export * from './ColumnValue'
|
|
6
6
|
export * from './Constraints'
|
|
7
7
|
export * from './ErrorUtils'
|
|
8
|
+
export * from './EventManager'
|
|
8
9
|
export * from './JunctionTableManager'
|
|
9
10
|
export * from './Mapper'
|
|
10
|
-
export * from '
|
|
11
|
+
export * from '../ExecutionContainer'
|
|
12
|
+
export * from './MapperFactory'
|
|
11
13
|
export * from './MutationProcessorHelper'
|
|
12
14
|
export * from './Result'
|
|
13
15
|
export * from './types'
|
|
@@ -6,6 +6,8 @@ import { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData }
|
|
|
6
6
|
import { ImplementationException } from '../../exception'
|
|
7
7
|
import { PredicateFactory } from '../../acl'
|
|
8
8
|
import { AbortDataManipulation, DataManipulationBuilder } from '../DataManipulationBuilder'
|
|
9
|
+
import { AfterInsertEvent, BeforeInsertEvent, EventManager } from '../EventManager'
|
|
10
|
+
import { Mapper } from '../Mapper'
|
|
9
11
|
|
|
10
12
|
export interface InsertResult {
|
|
11
13
|
values: ResolvedColumnValue[]
|
|
@@ -55,7 +57,7 @@ export class InsertBuilder implements DataManipulationBuilder {
|
|
|
55
57
|
return resolveRowData([...this.rowData.values()])
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
public async execute(
|
|
60
|
+
public async execute(mapper: Mapper): Promise<InsertResult> {
|
|
59
61
|
try {
|
|
60
62
|
const resolvedData = await this.getResolvedData()
|
|
61
63
|
if (resolvedData.find(it => it.resolvedValue === AbortDataManipulation)) {
|
|
@@ -83,8 +85,16 @@ export class InsertBuilder implements DataManipulationBuilder {
|
|
|
83
85
|
})
|
|
84
86
|
.returning(this.entity.primaryColumn)
|
|
85
87
|
|
|
86
|
-
const
|
|
88
|
+
const beforeInsertEvent = new BeforeInsertEvent(this.entity, resolvedData as ResolvedColumnValue[])
|
|
89
|
+
await mapper.eventManager.fire(beforeInsertEvent)
|
|
90
|
+
|
|
91
|
+
const returning = (await qb.execute(mapper.db)).map(it => it[this.entity.primaryColumn])
|
|
87
92
|
const result = returning.length === 1 ? returning[0] : null
|
|
93
|
+
|
|
94
|
+
const afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData as ResolvedColumnValue[], result)
|
|
95
|
+
beforeInsertEvent.afterEvent = afterInsertEvent
|
|
96
|
+
await mapper.eventManager.fire(afterInsertEvent)
|
|
97
|
+
|
|
88
98
|
this.resolver(result)
|
|
89
99
|
return { values: resolvedData as ResolvedColumnValue[], executed: true, primaryValue: result, aborted: false }
|
|
90
100
|
} catch (e) {
|
|
@@ -11,9 +11,8 @@ import { CreateInputVisitor } from '../../inputProcessing'
|
|
|
11
11
|
import { SqlCreateInputProcessor } from './SqlCreateInputProcessor'
|
|
12
12
|
import { Mapper } from '../Mapper'
|
|
13
13
|
import { Input, Model, Value } from '@contember/schema'
|
|
14
|
-
import { acceptEveryFieldVisitor, Providers } from '@contember/schema-utils'
|
|
14
|
+
import { acceptEveryFieldVisitor, Providers, SchemaDatabaseMetadata } from '@contember/schema-utils'
|
|
15
15
|
import { InsertBuilderFactory } from './InsertBuilderFactory'
|
|
16
|
-
import { Client } from '@contember/database'
|
|
17
16
|
import { InsertBuilder } from './InsertBuilder'
|
|
18
17
|
import { tryMutation } from '../ErrorUtils'
|
|
19
18
|
import { rowDataToFieldValues } from '../ColumnValue'
|
|
@@ -21,6 +20,7 @@ import { rowDataToFieldValues } from '../ColumnValue'
|
|
|
21
20
|
export class Inserter {
|
|
22
21
|
constructor(
|
|
23
22
|
private readonly schema: Model.Schema,
|
|
23
|
+
private readonly schemaDatabaseMetadata: SchemaDatabaseMetadata,
|
|
24
24
|
private readonly insertBuilderFactory: InsertBuilderFactory,
|
|
25
25
|
private readonly providers: Providers,
|
|
26
26
|
) {}
|
|
@@ -51,18 +51,18 @@ export class Inserter {
|
|
|
51
51
|
|
|
52
52
|
const okResultFactory = (primary: Value.PrimaryValue, values: RowValues) =>
|
|
53
53
|
new MutationCreateOk([], entity, primary, data, values)
|
|
54
|
-
const insertPromise = this.executeInsert(insertBuilder, mapper
|
|
54
|
+
const insertPromise = this.executeInsert(insertBuilder, mapper, okResultFactory)
|
|
55
55
|
|
|
56
|
-
return await collectResults(this.schema, insertPromise, Object.values(promises))
|
|
56
|
+
return await collectResults(this.schema, this.schemaDatabaseMetadata, insertPromise, Object.values(promises))
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
private async executeInsert(
|
|
60
60
|
insertBuilder: InsertBuilder,
|
|
61
|
-
|
|
61
|
+
mapper: Mapper,
|
|
62
62
|
okResultFactory: (primary: Value.PrimaryValue, values: RowValues) => MutationCreateOk,
|
|
63
63
|
): Promise<MutationResultList> {
|
|
64
|
-
return tryMutation(this.schema, async () => {
|
|
65
|
-
const result = await insertBuilder.execute(
|
|
64
|
+
return tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {
|
|
65
|
+
const result = await insertBuilder.execute(mapper)
|
|
66
66
|
if (result.aborted) {
|
|
67
67
|
return [new MutationNothingToDo([], NothingToDoReason.aborted)]
|
|
68
68
|
}
|
|
@@ -5,10 +5,11 @@ export class OrderByHelper {
|
|
|
5
5
|
public static appendDefaultOrderBy(
|
|
6
6
|
entity: Model.Entity,
|
|
7
7
|
objectNode: ObjectNode<Input.ListQueryInput>,
|
|
8
|
-
|
|
8
|
+
relationOrderBy: readonly Model.OrderBy[] | undefined,
|
|
9
9
|
): ObjectNode<Input.ListQueryInput> {
|
|
10
10
|
const inputOrder = objectNode.args.orderBy || []
|
|
11
11
|
const hasOrderBy = inputOrder.length > 0
|
|
12
|
+
const defaultOrderBy = relationOrderBy ?? entity.orderBy ?? []
|
|
12
13
|
if (!hasOrderBy && defaultOrderBy.length > 0) {
|
|
13
14
|
const defaultOrderByWithPrimary = [...defaultOrderBy, ...this.getPrimaryOrderBy(inputOrder, entity)]
|
|
14
15
|
return objectNode.withArg('orderBy', this.buildOrderBy(defaultOrderByWithPrimary))
|
|
@@ -83,7 +83,7 @@ export class RelationFetcher {
|
|
|
83
83
|
const objectNodeWithOrder = OrderByHelper.appendDefaultOrderBy(
|
|
84
84
|
targetEntity,
|
|
85
85
|
objectNodeWithWhere,
|
|
86
|
-
relation.orderBy
|
|
86
|
+
relation.orderBy,
|
|
87
87
|
)
|
|
88
88
|
|
|
89
89
|
return mapper.selectGrouped(targetEntity, objectNodeWithOrder, targetRelation, [
|
|
@@ -144,7 +144,7 @@ export class RelationFetcher {
|
|
|
144
144
|
}: FetchManyHasManyGroupsArgs): Promise<SelectGroupedObjects> {
|
|
145
145
|
const owningRelation = relationContext.type === 'manyHasManyInverse' ? relationContext.targetRelation : relationContext.relation
|
|
146
146
|
const joiningColumns = this.resolveJoiningColumns({ relationType: relationContext.type, joiningTable: owningRelation.joiningTable })
|
|
147
|
-
const defaultOrderBy = relationContext.relation.orderBy
|
|
147
|
+
const defaultOrderBy = relationContext.relation.orderBy
|
|
148
148
|
const objectNode = OrderByHelper.appendDefaultOrderBy(relationContext.targetEntity, field, defaultOrderBy)
|
|
149
149
|
const { targetEntity } = relationContext
|
|
150
150
|
const junctionValues = await this.fetchJunction(
|
|
@@ -6,6 +6,8 @@ import { PathFactory, WhereBuilder } from '../select'
|
|
|
6
6
|
import { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData } from '../ColumnValue'
|
|
7
7
|
import { PredicateFactory } from '../../acl'
|
|
8
8
|
import { AbortDataManipulation, DataManipulationBuilder } from '../DataManipulationBuilder'
|
|
9
|
+
import { AfterUpdateEvent, BeforeUpdateEvent, EventManager } from '../EventManager'
|
|
10
|
+
import { Mapper } from '../Mapper'
|
|
9
11
|
|
|
10
12
|
export interface UpdateResult {
|
|
11
13
|
values: ResolvedColumnValue[]
|
|
@@ -29,7 +31,7 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
29
31
|
private readonly schema: Model.Schema,
|
|
30
32
|
private readonly entity: Model.Entity,
|
|
31
33
|
private readonly whereBuilder: WhereBuilder,
|
|
32
|
-
private readonly
|
|
34
|
+
private readonly primary: Input.PrimaryValue,
|
|
33
35
|
private readonly pathFactory: PathFactory,
|
|
34
36
|
private readonly predicateFactory: PredicateFactory,
|
|
35
37
|
) {}
|
|
@@ -59,7 +61,7 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
59
61
|
this.addOldWhere(predicate)
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
public async execute(
|
|
64
|
+
public async execute(mapper: Mapper): Promise<UpdateResult> {
|
|
63
65
|
try {
|
|
64
66
|
const resolvedData = await resolveRowData<AbortDataManipulation>([...this.rowData.values()])
|
|
65
67
|
if (Object.keys(resolvedData).length === 0) {
|
|
@@ -70,12 +72,15 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
70
72
|
this.resolver(null)
|
|
71
73
|
return { values: [], affectedRows: null, executed: false, aborted: true }
|
|
72
74
|
}
|
|
75
|
+
const oldColSuffix = '_old__'
|
|
73
76
|
|
|
74
77
|
const qb = DbUpdateBuilder.create()
|
|
75
78
|
.with('newData_', qb => {
|
|
76
79
|
qb = resolvedData.reduce(
|
|
77
80
|
(qb, value) =>
|
|
78
|
-
qb
|
|
81
|
+
qb
|
|
82
|
+
.select(expr => expr.selectValue(value.resolvedValue as DbValue, value.columnType), value.columnName)
|
|
83
|
+
.select(['root_', value.columnName], value.columnName + oldColSuffix),
|
|
79
84
|
qb,
|
|
80
85
|
)
|
|
81
86
|
const columns = new Set(resolvedData.map(it => it.columnName))
|
|
@@ -97,7 +102,9 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
97
102
|
qb = remainingColumns.reduce((qb, columnName) => qb.select(['root_', columnName]), qb)
|
|
98
103
|
|
|
99
104
|
qb = this.whereBuilder.build(qb, this.entity, this.pathFactory.create([]), {
|
|
100
|
-
and: [
|
|
105
|
+
and: [{
|
|
106
|
+
[this.entity.primary]: { eq: this.primary },
|
|
107
|
+
}, this.oldWhere],
|
|
101
108
|
})
|
|
102
109
|
|
|
103
110
|
return qb
|
|
@@ -112,6 +119,7 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
112
119
|
{},
|
|
113
120
|
),
|
|
114
121
|
)
|
|
122
|
+
.returning(...resolvedData.map(it => it.columnName + oldColSuffix))
|
|
115
123
|
.from(qb => {
|
|
116
124
|
qb = qb.from('newData_')
|
|
117
125
|
const col1 = tuple(this.entity.tableName, this.entity.primaryColumn)
|
|
@@ -121,9 +129,24 @@ export class UpdateBuilder implements DataManipulationBuilder {
|
|
|
121
129
|
return qb
|
|
122
130
|
})
|
|
123
131
|
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
132
|
+
|
|
133
|
+
const beforeEvent = new BeforeUpdateEvent(this.entity, resolvedData as ResolvedColumnValue[], this.primary)
|
|
134
|
+
await mapper.eventManager.fire(beforeEvent)
|
|
135
|
+
|
|
136
|
+
const result = await qb.execute(mapper.db)
|
|
137
|
+
this.resolver(result.length)
|
|
138
|
+
|
|
139
|
+
if (result.length === 1) {
|
|
140
|
+
const eventData = (resolvedData as ResolvedColumnValue[]).map(it => ({
|
|
141
|
+
...it,
|
|
142
|
+
old: result[0][it.columnName + oldColSuffix],
|
|
143
|
+
}))
|
|
144
|
+
const afterUpdateEvent = new AfterUpdateEvent(this.entity, eventData, this.primary)
|
|
145
|
+
beforeEvent.afterEvent = afterUpdateEvent
|
|
146
|
+
await mapper.eventManager.fire(afterUpdateEvent)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return { values: resolvedData as ResolvedColumnValue[], affectedRows: result.length, executed: true, aborted: false }
|
|
127
150
|
} catch (e) {
|
|
128
151
|
this.resolver(null)
|
|
129
152
|
throw e
|
|
@@ -11,12 +11,12 @@ export class UpdateBuilderFactory {
|
|
|
11
11
|
private readonly predicateFactory: PredicateFactory,
|
|
12
12
|
) {}
|
|
13
13
|
|
|
14
|
-
public create(entity: Model.Entity,
|
|
14
|
+
public create(entity: Model.Entity, primary: Input.PrimaryValue): UpdateBuilder {
|
|
15
15
|
return new UpdateBuilder(
|
|
16
16
|
this.schema,
|
|
17
17
|
entity,
|
|
18
18
|
this.whereBuilder,
|
|
19
|
-
|
|
19
|
+
primary,
|
|
20
20
|
this.pathFactory,
|
|
21
21
|
this.predicateFactory,
|
|
22
22
|
)
|
|
@@ -4,8 +4,7 @@ import { Input, Model } from '@contember/schema'
|
|
|
4
4
|
import { PredicateFactory } from '../../acl'
|
|
5
5
|
import { UpdateBuilderFactory } from './UpdateBuilderFactory'
|
|
6
6
|
import { Mapper } from '../Mapper'
|
|
7
|
-
import { acceptEveryFieldVisitor } from '@contember/schema-utils'
|
|
8
|
-
import { Client } from '@contember/database'
|
|
7
|
+
import { acceptEveryFieldVisitor, SchemaDatabaseMetadata } from '@contember/schema-utils'
|
|
9
8
|
import {
|
|
10
9
|
collectResults,
|
|
11
10
|
MutationNoResultError,
|
|
@@ -22,6 +21,7 @@ import { rowDataToFieldValues } from '../ColumnValue'
|
|
|
22
21
|
export class Updater {
|
|
23
22
|
constructor(
|
|
24
23
|
private readonly schema: Model.Schema,
|
|
24
|
+
private readonly schemaDatabaseMetadata: SchemaDatabaseMetadata,
|
|
25
25
|
private readonly predicateFactory: PredicateFactory,
|
|
26
26
|
private readonly updateBuilderFactory: UpdateBuilderFactory,
|
|
27
27
|
) {}
|
|
@@ -33,9 +33,7 @@ export class Updater {
|
|
|
33
33
|
data: Input.UpdateDataInput,
|
|
34
34
|
filter?: Input.OptionalWhere,
|
|
35
35
|
): Promise<MutationResultList> {
|
|
36
|
-
const updateBuilder = this.updateBuilderFactory.create(entity,
|
|
37
|
-
[entity.primary]: { eq: primaryValue },
|
|
38
|
-
})
|
|
36
|
+
const updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)
|
|
39
37
|
|
|
40
38
|
const predicateFields = Object.keys(data)
|
|
41
39
|
updateBuilder.addPredicates(predicateFields)
|
|
@@ -48,12 +46,12 @@ export class Updater {
|
|
|
48
46
|
const promises = acceptEveryFieldVisitor<Promise<ResultListNotFlatten | undefined>>(this.schema, entity, visitor)
|
|
49
47
|
|
|
50
48
|
const okResultFactory = (values: RowValues) => new MutationUpdateOk([], entity, primaryValue, data, values)
|
|
51
|
-
const mutationResultPromise = Updater.executeUpdate(updateBuilder, mapper
|
|
49
|
+
const mutationResultPromise = Updater.executeUpdate(updateBuilder, mapper, okResultFactory)
|
|
52
50
|
const otherPromises = Object.values(promises)
|
|
53
51
|
if (otherPromises.length === 0) {
|
|
54
52
|
return await mutationResultPromise
|
|
55
53
|
} else {
|
|
56
|
-
return await collectResults(this.schema, mutationResultPromise, otherPromises)
|
|
54
|
+
return await collectResults(this.schema, this.schemaDatabaseMetadata, mutationResultPromise, otherPromises)
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -63,22 +61,20 @@ export class Updater {
|
|
|
63
61
|
primaryValue: Input.PrimaryValue,
|
|
64
62
|
builderCb: (builder: UpdateBuilder) => void,
|
|
65
63
|
): Promise<MutationResultList> {
|
|
66
|
-
const updateBuilder = this.updateBuilderFactory.create(entity,
|
|
67
|
-
[entity.primary]: { eq: primaryValue },
|
|
68
|
-
})
|
|
64
|
+
const updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)
|
|
69
65
|
|
|
70
66
|
const okResultFactory = (values: RowValues) => new MutationUpdateOk([], entity, primaryValue, {}, values)
|
|
71
67
|
builderCb(updateBuilder)
|
|
72
68
|
|
|
73
|
-
return Updater.executeUpdate(updateBuilder, mapper
|
|
69
|
+
return Updater.executeUpdate(updateBuilder, mapper, okResultFactory)
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
private static async executeUpdate(
|
|
77
73
|
updateBuilder: UpdateBuilder,
|
|
78
|
-
|
|
74
|
+
mapper: Mapper,
|
|
79
75
|
okResultFactory: (values: RowValues) => MutationUpdateOk,
|
|
80
76
|
): Promise<MutationResultList> {
|
|
81
|
-
const result = await updateBuilder.execute(
|
|
77
|
+
const result = await updateBuilder.execute(mapper)
|
|
82
78
|
if (result.aborted) {
|
|
83
79
|
return [new MutationNothingToDo([], NothingToDoReason.aborted)]
|
|
84
80
|
}
|
|
@@ -19,7 +19,6 @@ type NodeFilter = (node: GraphQlFieldNode, path: string[]) => boolean
|
|
|
19
19
|
type AnyNode = ObjectNode | FieldNode
|
|
20
20
|
|
|
21
21
|
export class GraphQlQueryAstFactory {
|
|
22
|
-
constructor(private readonly argumentValuesResolver: typeof getArgumentValues) {}
|
|
23
22
|
|
|
24
23
|
public create<Args = any>(info: GraphQLResolveInfo, filter?: NodeFilter): ObjectNode<Args> {
|
|
25
24
|
const node = ResolveInfoUtils.extractFieldNode(info)
|
|
@@ -53,7 +52,7 @@ export class GraphQlQueryAstFactory {
|
|
|
53
52
|
name,
|
|
54
53
|
alias,
|
|
55
54
|
fields,
|
|
56
|
-
|
|
55
|
+
getArgumentValues(field, node, info.variableValues),
|
|
57
56
|
field.extensions || {},
|
|
58
57
|
path,
|
|
59
58
|
)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Input, Model, Result, Value } from '@contember/schema'
|
|
2
2
|
import {
|
|
3
|
+
AfterCommitEvent,
|
|
4
|
+
BeforeCommitEvent,
|
|
3
5
|
ConstraintType,
|
|
4
6
|
getInsertPrimary,
|
|
5
7
|
InputErrorKind,
|
|
@@ -14,13 +16,14 @@ import { ValidationResolver } from './ValidationResolver'
|
|
|
14
16
|
import { GraphQLResolveInfo } from 'graphql'
|
|
15
17
|
import { GraphQlQueryAstFactory } from './GraphQlQueryAstFactory'
|
|
16
18
|
import { ImplementationException } from '../exception'
|
|
17
|
-
import {
|
|
19
|
+
import { retryTransaction } from '@contember/database'
|
|
18
20
|
import { Operation, readOperationMeta } from '../schema'
|
|
19
21
|
import { assertNever } from '../utils'
|
|
20
22
|
import { InputPreValidator } from '../input-validation'
|
|
21
23
|
import { ObjectNode } from '../inputProcessing'
|
|
22
24
|
import { executeReadOperations } from './ReadHelpers'
|
|
23
25
|
import { logger } from '@contember/logger'
|
|
26
|
+
import { SchemaDatabaseMetadata } from '@contember/schema-utils'
|
|
24
27
|
|
|
25
28
|
type WithoutNode<T extends { node: any }> = Pick<T, Exclude<keyof T, 'node'>>
|
|
26
29
|
|
|
@@ -29,11 +32,10 @@ type TransactionOptions = { deferForeignKeyConstraints?: boolean }
|
|
|
29
32
|
export class MutationResolver {
|
|
30
33
|
constructor(
|
|
31
34
|
private readonly schema: Model.Schema,
|
|
32
|
-
private readonly db: Client,
|
|
33
35
|
private readonly mapperFactory: MapperFactory,
|
|
34
|
-
private readonly systemVariablesSetup: (db: Client) => Promise<void>,
|
|
35
36
|
private readonly inputValidator: InputPreValidator,
|
|
36
37
|
private readonly graphqlQueryAstFactory: GraphQlQueryAstFactory,
|
|
38
|
+
private readonly schemaDatabaseMetadata: SchemaDatabaseMetadata,
|
|
37
39
|
) {}
|
|
38
40
|
|
|
39
41
|
public async resolveTransaction(info: GraphQLResolveInfo, options: TransactionOptions): Promise<Result.TransactionResult> {
|
|
@@ -60,7 +62,7 @@ export class MutationResolver {
|
|
|
60
62
|
: undefined,
|
|
61
63
|
}))
|
|
62
64
|
|
|
63
|
-
return this.transaction(async
|
|
65
|
+
return this.transaction(async mapper => {
|
|
64
66
|
if (options?.deferForeignKeyConstraints) {
|
|
65
67
|
logger.debug('MutationResolver: deferring foreign constraints')
|
|
66
68
|
await mapper.constraintHelper.setFkConstraintsDeferred()
|
|
@@ -196,7 +198,7 @@ export class MutationResolver {
|
|
|
196
198
|
}
|
|
197
199
|
if (options?.deferForeignKeyConstraints) {
|
|
198
200
|
logger.debug('MutationResolver: validating fk constraints')
|
|
199
|
-
const constraintsResult = await tryMutation(this.schema, async () => {
|
|
201
|
+
const constraintsResult = await tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {
|
|
200
202
|
await mapper.constraintHelper.setFkConstraintsImmediate()
|
|
201
203
|
return []
|
|
202
204
|
})
|
|
@@ -468,25 +470,24 @@ export class MutationResolver {
|
|
|
468
470
|
}
|
|
469
471
|
|
|
470
472
|
private async transaction<R extends { ok: boolean }>(
|
|
471
|
-
cb: (mapper: Mapper
|
|
473
|
+
cb: (mapper: Mapper) => Promise<R>,
|
|
472
474
|
): Promise<R> {
|
|
473
475
|
return await retryTransaction(
|
|
474
476
|
async () => {
|
|
475
|
-
|
|
477
|
+
const [result, mapper] = await this.mapperFactory.transaction(async mapper => {
|
|
476
478
|
logger.debug('MutationResolver: Starting mutation transaction')
|
|
477
|
-
await
|
|
478
|
-
await this.systemVariablesSetup(trx)
|
|
479
|
-
const mapper = this.mapperFactory(trx)
|
|
480
|
-
|
|
481
|
-
const result = await cb(mapper, trx)
|
|
479
|
+
const result = await cb(mapper)
|
|
482
480
|
if (!result.ok) {
|
|
483
481
|
logger.debug('MutationResolver: Transaction failed, rolling back', { result })
|
|
484
|
-
await
|
|
482
|
+
await mapper.db.connection.rollback()
|
|
485
483
|
} else {
|
|
486
484
|
logger.debug('MutationResolver: Transaction ok, committing')
|
|
487
485
|
}
|
|
488
|
-
|
|
486
|
+
await mapper.eventManager.fire(new BeforeCommitEvent())
|
|
487
|
+
return [result, mapper]
|
|
489
488
|
})
|
|
489
|
+
await mapper.eventManager.fire(new AfterCommitEvent())
|
|
490
|
+
return result
|
|
490
491
|
},
|
|
491
492
|
message => logger.warn(message),
|
|
492
493
|
{
|
|
@@ -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:
|
|
10
|
-
timer: <T>(event: string, cb
|
|
8
|
+
executionContainer: ExecutionContainer
|
|
9
|
+
timer: <T>(event: string, cb: () => T) => T
|
|
11
10
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -15,5 +15,5 @@ export const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Enti
|
|
|
15
15
|
}),
|
|
16
16
|
).filter((it): it is [string] => !!it)
|
|
17
17
|
|
|
18
|
-
return [[entity.primary], ...
|
|
18
|
+
return [[entity.primary], ...entity.unique.map(it => it.fields), ...relations]
|
|
19
19
|
}
|