Skip to content

Commit

Permalink
fix(client-content): fix building transaction fields
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Dec 14, 2023
1 parent d774a45 commit 8023497
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 43 deletions.
8 changes: 6 additions & 2 deletions packages/client-content/src/ContentQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export class ContentQueryBuilder {
const transactionArgs = createTypedArgs({ options }, {
options: 'MutationTransactionOptions',
})
return new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, combined.selection, ({ ok, errorMessage, errors, validation, ...data }) => {
const items = [
...this.createMutationSelection('transaction'),
...combined.selection,
]
return new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {
return {
ok,
errorMessage,
Expand All @@ -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'),
Expand Down
163 changes: 122 additions & 41 deletions packages/client-content/tests/cases/unit/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(`
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8023497

Please sign in to comment.