diff --git a/packages/client-content/src/ContentQueryBuilder.ts b/packages/client-content/src/ContentQueryBuilder.ts index 199832128e..6533b4f191 100644 --- a/packages/client-content/src/ContentQueryBuilder.ts +++ b/packages/client-content/src/ContentQueryBuilder.ts @@ -147,7 +147,11 @@ export class ContentQueryBuilder { const transactionArgs = createTypedArgs({ options }, { options: 'MutationTransactionOptions', }) - return new ContentOperation, 'mutation'>('mutation', 'transaction', transactionArgs, combined.selection, ({ ok, errorMessage, errors, validation, ...data }) => { + const items = [ + ...this.createMutationSelection('transaction'), + ...combined.selection, + ] + return new ContentOperation, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => { return { ok, errorMessage, @@ -158,7 +162,7 @@ export class ContentQueryBuilder { }) } - private createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert', selection?: GraphQlSelectionSet): GraphQlSelectionSet { + private createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert' | 'transaction', selection?: GraphQlSelectionSet): GraphQlSelectionSet { const items: GraphQlSelectionSet = [ new GraphQlField(null, 'ok'), new GraphQlField(null, 'errorMessage'), diff --git a/packages/client-content/tests/cases/unit/mutation.test.ts b/packages/client-content/tests/cases/unit/mutation.test.ts index 848257810e..7418e9fdc8 100644 --- a/packages/client-content/tests/cases/unit/mutation.test.ts +++ b/packages/client-content/tests/cases/unit/mutation.test.ts @@ -24,6 +24,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } mut: createAuthor(data: $data_AuthorCreateInput_1) { ok errorMessage @@ -101,6 +109,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } mut: createAuthor(data: $data_AuthorCreateInput_1) { ok errorMessage @@ -179,6 +195,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $data_AuthorUpdateInput_2: AuthorUpdateInput!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } mut: updateAuthor(by: $by_AuthorUniqueWhere_1, data: $data_AuthorUpdateInput_2) { ok errorMessage @@ -253,6 +277,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } mut: deleteAuthor(by: $by_AuthorUniqueWhere_1) { ok errorMessage @@ -275,6 +307,23 @@ describe('mutations in trx', () => { message type } + fragment ValidationResult on _ValidationResult { + valid + errors { + path { + ... on _FieldPathFragment { + field + } + ... on _IndexPathFragment { + index + alias + } + } + message { + text + } + } + } " `) expect(calls[0].variables).toMatchInlineSnapshot(` @@ -309,52 +358,60 @@ describe('mutations in trx', () => { }))) expect(calls).toHaveLength(1) expect(calls[0].query).toMatchInlineSnapshot(` - "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $create_AuthorCreateInput_2: AuthorCreateInput!, $update_AuthorUpdateInput_3: AuthorUpdateInput!) { - mut: transaction(options: $options_MutationTransactionOptions_0) { - mut: upsertAuthor(by: $by_AuthorUniqueWhere_1, create: $create_AuthorCreateInput_2, update: $update_AuthorUpdateInput_3) { - ok - errorMessage - errors { - ... MutationError - } - validation { - ... ValidationResult - } - } - } + "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $create_AuthorCreateInput_2: AuthorCreateInput!, $update_AuthorUpdateInput_3: AuthorUpdateInput!) { + mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError } - fragment MutationError on _MutationError { - paths { - ... on _FieldPathFragment { - field - } - ... on _IndexPathFragment { - index - alias - } - } - message - type + validation { + ... ValidationResult } - fragment ValidationResult on _ValidationResult { - valid + mut: upsertAuthor(by: $by_AuthorUniqueWhere_1, create: $create_AuthorCreateInput_2, update: $update_AuthorUpdateInput_3) { + ok + errorMessage errors { - path { - ... on _FieldPathFragment { - field - } - ... on _IndexPathFragment { - index - alias - } - } - message { - text - } + ... MutationError + } + validation { + ... ValidationResult } } - " - `) + } + } + fragment MutationError on _MutationError { + paths { + ... on _FieldPathFragment { + field + } + ... on _IndexPathFragment { + index + alias + } + } + message + type + } + fragment ValidationResult on _ValidationResult { + valid + errors { + path { + ... on _FieldPathFragment { + field + } + ... on _IndexPathFragment { + index + alias + } + } + message { + text + } + } + } + " + `) expect(calls[0].variables).toMatchInlineSnapshot(` { "by_AuthorUniqueWhere_1": { @@ -407,6 +464,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!, $data_AuthorCreateInput_2: AuthorCreateInput!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } mut_0: createAuthor(data: $data_AuthorCreateInput_1) { ok errorMessage @@ -508,6 +573,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!, $data_PostCreateInput_2: PostCreateInput!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } createAuthor(data: $data_AuthorCreateInput_1) { ok errorMessage @@ -613,6 +686,14 @@ describe('mutations in trx', () => { expect(calls[0].query).toMatchInlineSnapshot(` "mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_PostCreateInput_1: PostCreateInput!, $by_PostUniqueWhere_2: PostUniqueWhere!) { mut: transaction(options: $options_MutationTransactionOptions_0) { + ok + errorMessage + errors { + ... MutationError + } + validation { + ... ValidationResult + } createPost(data: $data_PostCreateInput_1) { ok errorMessage