@contember/client-content 2.0.0-alpha.4 → 2.0.0-alpha.40
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/api-extractor.json +3 -0
- package/dist/development/index.cjs +5 -5
- package/dist/development/index.js +5 -5
- package/dist/development/src/ContentClient.cjs.map +1 -0
- package/dist/development/src/ContentClient.js.map +1 -0
- package/dist/development/src/ContentQueryBuilder.cjs.map +1 -0
- package/dist/development/src/ContentQueryBuilder.js.map +1 -0
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/development/src/nodes/ContentOperation.cjs.map +1 -0
- package/dist/development/src/nodes/ContentOperation.js.map +1 -0
- package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/development/src/utils/ContentOperationSet.js.map +1 -0
- package/dist/development/src/utils/createListArgs.cjs.map +1 -0
- package/dist/development/src/utils/createListArgs.js.map +1 -0
- package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/development/src/utils/createMutationOperationSet.js.map +1 -0
- package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/development/src/utils/createQueryOperationSet.js.map +1 -0
- package/dist/development/src/utils/createTypedArgs.cjs.map +1 -0
- package/dist/development/src/utils/createTypedArgs.js.map +1 -0
- package/dist/development/src/utils/mutationFragments.cjs.map +1 -0
- package/dist/development/src/utils/mutationFragments.js.map +1 -0
- package/dist/production/index.cjs +5 -5
- package/dist/production/index.js +5 -5
- package/dist/production/src/ContentClient.cjs.map +1 -0
- package/dist/production/src/ContentClient.js.map +1 -0
- package/dist/production/src/ContentQueryBuilder.cjs.map +1 -0
- package/dist/production/src/ContentQueryBuilder.js.map +1 -0
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/production/src/nodes/ContentOperation.cjs.map +1 -0
- package/dist/production/src/nodes/ContentOperation.js.map +1 -0
- package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/production/src/utils/ContentOperationSet.js.map +1 -0
- package/dist/production/src/utils/createListArgs.cjs.map +1 -0
- package/dist/production/src/utils/createListArgs.js.map +1 -0
- package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/production/src/utils/createMutationOperationSet.js.map +1 -0
- package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/production/src/utils/createQueryOperationSet.js.map +1 -0
- package/dist/production/src/utils/createTypedArgs.cjs.map +1 -0
- package/dist/production/src/utils/createTypedArgs.js.map +1 -0
- package/dist/production/src/utils/mutationFragments.cjs.map +1 -0
- package/dist/production/src/utils/mutationFragments.js.map +1 -0
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
- package/dist/types/nodes/ContentOperation.d.ts.map +1 -1
- package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/Schema.d.ts +6 -3
- package/dist/types/types/Schema.d.ts.map +1 -1
- package/dist/types/utils/createListArgs.d.ts +1 -1
- package/dist/types/utils/createListArgs.d.ts.map +1 -1
- package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -1
- package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -1
- package/dist/types/utils/createTypedArgs.d.ts.map +1 -1
- package/package.json +10 -17
- package/src/ContentQueryBuilder.ts +1 -1
- package/src/nodes/TypedEntitySelection.ts +1 -1
- package/src/tsconfig.json +3 -0
- package/src/types/Schema.ts +6 -3
- package/src/utils/createListArgs.ts +1 -1
- package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +1198 -0
- package/tests/cases/unit/__snapshots__/query.test.ts.snap +102 -0
- package/tests/cases/unit/mutation.test.ts +521 -0
- package/tests/cases/unit/query.test.ts +450 -0
- package/tests/cases/unit/types.test.ts +145 -0
- package/tests/client/entities.ts +108 -0
- package/tests/client/enums.ts +3 -0
- package/tests/client/index.ts +17 -0
- package/tests/client/names.ts +117 -0
- package/tests/generate.ts +13 -0
- package/tests/lib.ts +16 -0
- package/tests/schema.ts +37 -0
- package/tests/tsconfig.json +13 -0
- package/tsconfig.json +8 -0
- package/tsdoc.json +6 -0
- package/vitest.config.ts +3 -0
- package/dist/development/ContentClient.cjs.map +0 -1
- package/dist/development/ContentClient.js.map +0 -1
- package/dist/development/ContentQueryBuilder.cjs.map +0 -1
- package/dist/development/ContentQueryBuilder.js.map +0 -1
- package/dist/development/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/development/nodes/ContentEntitySelection.js.map +0 -1
- package/dist/development/nodes/ContentOperation.cjs.map +0 -1
- package/dist/development/nodes/ContentOperation.js.map +0 -1
- package/dist/development/utils/ContentOperationSet.cjs.map +0 -1
- package/dist/development/utils/ContentOperationSet.js.map +0 -1
- package/dist/development/utils/createListArgs.cjs.map +0 -1
- package/dist/development/utils/createListArgs.js.map +0 -1
- package/dist/development/utils/createMutationOperationSet.cjs.map +0 -1
- package/dist/development/utils/createMutationOperationSet.js.map +0 -1
- package/dist/development/utils/createQueryOperationSet.cjs.map +0 -1
- package/dist/development/utils/createQueryOperationSet.js.map +0 -1
- package/dist/development/utils/createTypedArgs.cjs.map +0 -1
- package/dist/development/utils/createTypedArgs.js.map +0 -1
- package/dist/development/utils/mutationFragments.cjs.map +0 -1
- package/dist/development/utils/mutationFragments.js.map +0 -1
- package/dist/production/ContentClient.cjs.map +0 -1
- package/dist/production/ContentClient.js.map +0 -1
- package/dist/production/ContentQueryBuilder.cjs.map +0 -1
- package/dist/production/ContentQueryBuilder.js.map +0 -1
- package/dist/production/nodes/ContentEntitySelection.cjs.map +0 -1
- package/dist/production/nodes/ContentEntitySelection.js.map +0 -1
- package/dist/production/nodes/ContentOperation.cjs.map +0 -1
- package/dist/production/nodes/ContentOperation.js.map +0 -1
- package/dist/production/utils/ContentOperationSet.cjs.map +0 -1
- package/dist/production/utils/ContentOperationSet.js.map +0 -1
- package/dist/production/utils/createListArgs.cjs.map +0 -1
- package/dist/production/utils/createListArgs.js.map +0 -1
- package/dist/production/utils/createMutationOperationSet.cjs.map +0 -1
- package/dist/production/utils/createMutationOperationSet.js.map +0 -1
- package/dist/production/utils/createQueryOperationSet.cjs.map +0 -1
- package/dist/production/utils/createQueryOperationSet.js.map +0 -1
- package/dist/production/utils/createTypedArgs.cjs.map +0 -1
- package/dist/production/utils/createTypedArgs.js.map +0 -1
- package/dist/production/utils/mutationFragments.cjs.map +0 -1
- package/dist/production/utils/mutationFragments.js.map +0 -1
- /package/dist/development/{ContentClient.cjs → src/ContentClient.cjs} +0 -0
- /package/dist/development/{ContentClient.js → src/ContentClient.js} +0 -0
- /package/dist/development/{ContentQueryBuilder.cjs → src/ContentQueryBuilder.cjs} +0 -0
- /package/dist/development/{ContentQueryBuilder.js → src/ContentQueryBuilder.js} +0 -0
- /package/dist/development/{nodes → src/nodes}/ContentEntitySelection.cjs +0 -0
- /package/dist/development/{nodes → src/nodes}/ContentEntitySelection.js +0 -0
- /package/dist/development/{nodes → src/nodes}/ContentOperation.cjs +0 -0
- /package/dist/development/{nodes → src/nodes}/ContentOperation.js +0 -0
- /package/dist/development/{utils → src/utils}/ContentOperationSet.cjs +0 -0
- /package/dist/development/{utils → src/utils}/ContentOperationSet.js +0 -0
- /package/dist/development/{utils → src/utils}/createListArgs.cjs +0 -0
- /package/dist/development/{utils → src/utils}/createListArgs.js +0 -0
- /package/dist/development/{utils → src/utils}/createMutationOperationSet.cjs +0 -0
- /package/dist/development/{utils → src/utils}/createMutationOperationSet.js +0 -0
- /package/dist/development/{utils → src/utils}/createQueryOperationSet.cjs +0 -0
- /package/dist/development/{utils → src/utils}/createQueryOperationSet.js +0 -0
- /package/dist/development/{utils → src/utils}/createTypedArgs.cjs +0 -0
- /package/dist/development/{utils → src/utils}/createTypedArgs.js +0 -0
- /package/dist/development/{utils → src/utils}/mutationFragments.cjs +0 -0
- /package/dist/development/{utils → src/utils}/mutationFragments.js +0 -0
- /package/dist/production/{ContentClient.cjs → src/ContentClient.cjs} +0 -0
- /package/dist/production/{ContentClient.js → src/ContentClient.js} +0 -0
- /package/dist/production/{ContentQueryBuilder.cjs → src/ContentQueryBuilder.cjs} +0 -0
- /package/dist/production/{ContentQueryBuilder.js → src/ContentQueryBuilder.js} +0 -0
- /package/dist/production/{nodes → src/nodes}/ContentEntitySelection.cjs +0 -0
- /package/dist/production/{nodes → src/nodes}/ContentEntitySelection.js +0 -0
- /package/dist/production/{nodes → src/nodes}/ContentOperation.cjs +0 -0
- /package/dist/production/{nodes → src/nodes}/ContentOperation.js +0 -0
- /package/dist/production/{utils → src/utils}/ContentOperationSet.cjs +0 -0
- /package/dist/production/{utils → src/utils}/ContentOperationSet.js +0 -0
- /package/dist/production/{utils → src/utils}/createListArgs.cjs +0 -0
- /package/dist/production/{utils → src/utils}/createListArgs.js +0 -0
- /package/dist/production/{utils → src/utils}/createMutationOperationSet.cjs +0 -0
- /package/dist/production/{utils → src/utils}/createMutationOperationSet.js +0 -0
- /package/dist/production/{utils → src/utils}/createQueryOperationSet.cjs +0 -0
- /package/dist/production/{utils → src/utils}/createQueryOperationSet.js +0 -0
- /package/dist/production/{utils → src/utils}/createTypedArgs.cjs +0 -0
- /package/dist/production/{utils → src/utils}/createTypedArgs.js +0 -0
- /package/dist/production/{utils → src/utils}/mutationFragments.cjs +0 -0
- /package/dist/production/{utils → src/utils}/mutationFragments.js +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`queries list 1`] = `
|
|
4
|
+
"query {
|
|
5
|
+
\tauthors: listAuthor {
|
|
6
|
+
\t\tid
|
|
7
|
+
\t\tname
|
|
8
|
+
\t\temail
|
|
9
|
+
\t}
|
|
10
|
+
}
|
|
11
|
+
"
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
exports[`queries multiple queries 1`] = `
|
|
15
|
+
"query {
|
|
16
|
+
\tauthors: listAuthor {
|
|
17
|
+
\t\tid
|
|
18
|
+
\t\tname
|
|
19
|
+
\t\temail
|
|
20
|
+
\t}
|
|
21
|
+
\tposts: listPost {
|
|
22
|
+
\t\tid
|
|
23
|
+
\t\tpublishedAt
|
|
24
|
+
\t}
|
|
25
|
+
}
|
|
26
|
+
"
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`queries single query 1`] = `
|
|
30
|
+
"query {
|
|
31
|
+
\tvalue: listPost {
|
|
32
|
+
\t\tid
|
|
33
|
+
\t\tpublishedAt
|
|
34
|
+
\t}
|
|
35
|
+
}
|
|
36
|
+
"
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
exports[`queries nested object 1`] = `
|
|
40
|
+
"query {
|
|
41
|
+
\tauthors: listAuthor {
|
|
42
|
+
\t\tid
|
|
43
|
+
\t\tname
|
|
44
|
+
\t\temail
|
|
45
|
+
\t\tposts {
|
|
46
|
+
\t\t\tid
|
|
47
|
+
\t\t\tpublishedAt
|
|
48
|
+
\t\t\ttags {
|
|
49
|
+
\t\t\t\tid
|
|
50
|
+
\t\t\t\tname
|
|
51
|
+
\t\t\t}
|
|
52
|
+
\t\t}
|
|
53
|
+
\t}
|
|
54
|
+
}
|
|
55
|
+
"
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
exports[`queries nested object args 1`] = `
|
|
59
|
+
"query($PostWhere_0: PostWhere, $Int_1: Int) {
|
|
60
|
+
\tauthors: listAuthor {
|
|
61
|
+
\t\tid
|
|
62
|
+
\t\tname
|
|
63
|
+
\t\temail
|
|
64
|
+
\t\tposts(filter: $PostWhere_0, limit: $Int_1) {
|
|
65
|
+
\t\t\tid
|
|
66
|
+
\t\t\tpublishedAt
|
|
67
|
+
\t\t}
|
|
68
|
+
\t}
|
|
69
|
+
}
|
|
70
|
+
"
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
exports[`queries list with args:
|
|
74
|
+
\t\t\t"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
|
|
75
|
+
\t\t\t\tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
|
|
76
|
+
\t\t\t\t\tid
|
|
77
|
+
\t\t\t\t\tname
|
|
78
|
+
\t\t\t\t\temail
|
|
79
|
+
\t\t\t\t}
|
|
80
|
+
\t\t\t}
|
|
81
|
+
\t\t\t"
|
|
82
|
+
\t\t 1`] = `
|
|
83
|
+
"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
|
|
84
|
+
\tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
|
|
85
|
+
\t\tid
|
|
86
|
+
\t\tname
|
|
87
|
+
\t\temail
|
|
88
|
+
\t}
|
|
89
|
+
}
|
|
90
|
+
"
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
exports[`queries get by id 1`] = `
|
|
94
|
+
"query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
|
|
95
|
+
\tauthors: getAuthor(by: $AuthorUniqueWhere_0) {
|
|
96
|
+
\t\tid
|
|
97
|
+
\t\tname
|
|
98
|
+
\t\temail
|
|
99
|
+
\t}
|
|
100
|
+
}
|
|
101
|
+
"
|
|
102
|
+
`;
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { createClient } from '../../lib'
|
|
3
|
+
import { queryBuilder } from '../../client'
|
|
4
|
+
|
|
5
|
+
const qb = queryBuilder
|
|
6
|
+
describe('mutations in trx', () => {
|
|
7
|
+
test('create trx', async () => {
|
|
8
|
+
const [client, calls] = createClient({
|
|
9
|
+
mut: {
|
|
10
|
+
ok: true,
|
|
11
|
+
mut: {
|
|
12
|
+
ok: true,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
const createAuthor = qb.transaction(qb.create('Author', {
|
|
17
|
+
data: {
|
|
18
|
+
name: 'John',
|
|
19
|
+
email: 'xx@localhost',
|
|
20
|
+
},
|
|
21
|
+
}))
|
|
22
|
+
const result = await client.mutate(createAuthor)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
expect(result.data.ok).toBe(true)
|
|
26
|
+
expect(calls).toHaveLength(1)
|
|
27
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
28
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('mutation with a node', async () => {
|
|
32
|
+
const [client, calls] = createClient({
|
|
33
|
+
mut: {
|
|
34
|
+
ok: true,
|
|
35
|
+
mut: {
|
|
36
|
+
ok: true,
|
|
37
|
+
node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
const result = await client.mutate(qb.transaction(qb.create('Author', {
|
|
42
|
+
data: {
|
|
43
|
+
name: 'John',
|
|
44
|
+
email: 'xx@localhost',
|
|
45
|
+
},
|
|
46
|
+
}, it => it.$('id'))))
|
|
47
|
+
expect(result.ok).toBe(true)
|
|
48
|
+
expect(result.data?.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
|
|
49
|
+
expect(calls).toHaveLength(1)
|
|
50
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
51
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('update', async () => {
|
|
55
|
+
const [client, calls] = createClient({
|
|
56
|
+
mut: {
|
|
57
|
+
ok: true,
|
|
58
|
+
mut: {
|
|
59
|
+
ok: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
await client.mutate(qb.transaction(qb.update('Author', {
|
|
64
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
65
|
+
data: {
|
|
66
|
+
name: 'John',
|
|
67
|
+
email: 'xx@localhost',
|
|
68
|
+
},
|
|
69
|
+
})))
|
|
70
|
+
expect(calls).toHaveLength(1)
|
|
71
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
72
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('delete', async () => {
|
|
76
|
+
const [client, calls] = createClient({
|
|
77
|
+
mut: {
|
|
78
|
+
ok: true,
|
|
79
|
+
mut: {
|
|
80
|
+
ok: true,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
await client.mutate(qb.transaction(qb.delete('Author', {
|
|
85
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
86
|
+
})))
|
|
87
|
+
expect(calls).toHaveLength(1)
|
|
88
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
89
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('upsert', async () => {
|
|
93
|
+
const [client, calls] = createClient({
|
|
94
|
+
mut: {
|
|
95
|
+
ok: true,
|
|
96
|
+
mut: {
|
|
97
|
+
ok: true,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
await client.mutate(qb.transaction(qb.upsert('Author', {
|
|
102
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
103
|
+
create: {
|
|
104
|
+
name: 'John',
|
|
105
|
+
email: 'xx@localhost',
|
|
106
|
+
},
|
|
107
|
+
update: {
|
|
108
|
+
name: 'John',
|
|
109
|
+
email: 'xx@localhost',
|
|
110
|
+
},
|
|
111
|
+
})))
|
|
112
|
+
expect(calls).toHaveLength(1)
|
|
113
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
114
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('multiple mutations as array', async () => {
|
|
118
|
+
const [client, calls] = createClient({
|
|
119
|
+
mut: {
|
|
120
|
+
ok: true,
|
|
121
|
+
mut_0: {
|
|
122
|
+
ok: true,
|
|
123
|
+
},
|
|
124
|
+
mut_1: {
|
|
125
|
+
ok: true,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
const result = await client.mutate(qb.transaction([
|
|
130
|
+
qb.create('Author', {
|
|
131
|
+
data: {
|
|
132
|
+
name: 'John',
|
|
133
|
+
email: 'xx@localhost',
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
qb.create('Author', {
|
|
137
|
+
data: {
|
|
138
|
+
name: 'John',
|
|
139
|
+
email: 'xx@localhost',
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
]))
|
|
143
|
+
expect(result.ok).toBe(true)
|
|
144
|
+
expect(result.data).toHaveLength(2)
|
|
145
|
+
expect(result.data[0].ok).toBe(true)
|
|
146
|
+
expect(result.data[1].ok).toBe(true)
|
|
147
|
+
expect(calls).toHaveLength(1)
|
|
148
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
149
|
+
expect(calls[0].variables).toMatchSnapshot(`
|
|
150
|
+
{
|
|
151
|
+
"AuthorCreateInput_1": {
|
|
152
|
+
"email": "xx@localhost",
|
|
153
|
+
"name": "John",
|
|
154
|
+
},
|
|
155
|
+
"AuthorCreateInput_2": {
|
|
156
|
+
"email": "xx@localhost",
|
|
157
|
+
"name": "John",
|
|
158
|
+
},
|
|
159
|
+
"MutationTransactionOptions_0": {},
|
|
160
|
+
}
|
|
161
|
+
`)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('multiple named mutations trx', async () => {
|
|
165
|
+
const [client, calls] = createClient({
|
|
166
|
+
mut: {
|
|
167
|
+
ok: true,
|
|
168
|
+
createAuthor: {
|
|
169
|
+
ok: true,
|
|
170
|
+
},
|
|
171
|
+
createPost: {
|
|
172
|
+
ok: true,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
const result = await client.mutate(qb.transaction({
|
|
177
|
+
createAuthor: qb.create('Author', {
|
|
178
|
+
data: {
|
|
179
|
+
name: 'John',
|
|
180
|
+
email: 'xx@localhost',
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
createPost: qb.create('Post', {
|
|
184
|
+
data: {
|
|
185
|
+
publishedAt: 'now',
|
|
186
|
+
},
|
|
187
|
+
}),
|
|
188
|
+
}))
|
|
189
|
+
expect(result.data.createAuthor.ok).toBe(true)
|
|
190
|
+
expect(result.data.createPost.ok).toBe(true)
|
|
191
|
+
expect(calls).toHaveLength(1)
|
|
192
|
+
expect(calls[0].query).toMatchSnapshot(`
|
|
193
|
+
"mutation($MutationTransactionOptions_0: MutationTransactionOptions, $AuthorCreateInput_1: AuthorCreateInput!, $PostCreateInput_2: PostCreateInput!) {
|
|
194
|
+
mut: transaction(options: $MutationTransactionOptions_0) {
|
|
195
|
+
ok
|
|
196
|
+
errorMessage
|
|
197
|
+
errors {
|
|
198
|
+
... MutationError
|
|
199
|
+
}
|
|
200
|
+
validation {
|
|
201
|
+
... ValidationResult
|
|
202
|
+
}
|
|
203
|
+
createAuthor(data: $AuthorCreateInput_1) {
|
|
204
|
+
ok
|
|
205
|
+
errorMessage
|
|
206
|
+
errors {
|
|
207
|
+
... MutationError
|
|
208
|
+
}
|
|
209
|
+
validation {
|
|
210
|
+
... ValidationResult
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
createPost(data: $PostCreateInput_2) {
|
|
214
|
+
ok
|
|
215
|
+
errorMessage
|
|
216
|
+
errors {
|
|
217
|
+
... MutationError
|
|
218
|
+
}
|
|
219
|
+
validation {
|
|
220
|
+
... ValidationResult
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
fragment MutationError on _MutationError {
|
|
226
|
+
paths {
|
|
227
|
+
... on _FieldPathFragment {
|
|
228
|
+
field
|
|
229
|
+
}
|
|
230
|
+
... on _IndexPathFragment {
|
|
231
|
+
index
|
|
232
|
+
alias
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
message
|
|
236
|
+
type
|
|
237
|
+
}
|
|
238
|
+
fragment ValidationResult on _ValidationResult {
|
|
239
|
+
valid
|
|
240
|
+
errors {
|
|
241
|
+
path {
|
|
242
|
+
... on _FieldPathFragment {
|
|
243
|
+
field
|
|
244
|
+
}
|
|
245
|
+
... on _IndexPathFragment {
|
|
246
|
+
index
|
|
247
|
+
alias
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
message {
|
|
251
|
+
text
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
"
|
|
256
|
+
`)
|
|
257
|
+
expect(calls[0].variables).toMatchSnapshot(`
|
|
258
|
+
{
|
|
259
|
+
"AuthorCreateInput_1": {
|
|
260
|
+
"email": "xx@localhost",
|
|
261
|
+
"name": "John",
|
|
262
|
+
},
|
|
263
|
+
"MutationTransactionOptions_0": {},
|
|
264
|
+
"PostCreateInput_2": {
|
|
265
|
+
"publishedAt": "now",
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
`)
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('mutation and query combo trx', async () => {
|
|
272
|
+
const [client, calls] = createClient({
|
|
273
|
+
mut: {
|
|
274
|
+
ok: true,
|
|
275
|
+
createPost: {
|
|
276
|
+
ok: true,
|
|
277
|
+
},
|
|
278
|
+
post: {
|
|
279
|
+
value: {
|
|
280
|
+
id: 'ca7a9b84-efbb-435d-a063-da11f205335a',
|
|
281
|
+
publishedAt: 'now',
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
const trx = qb.transaction({
|
|
288
|
+
createPost: qb.create('Post', {
|
|
289
|
+
data: {
|
|
290
|
+
publishedAt: 'now',
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
post: qb.get('Post', {
|
|
294
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
295
|
+
}, it => it.$$()),
|
|
296
|
+
})
|
|
297
|
+
const result = await client.mutate(trx)
|
|
298
|
+
expect(result.data.createPost.ok).toBe(true)
|
|
299
|
+
expect(result.data.post?.publishedAt).toBe('now')
|
|
300
|
+
|
|
301
|
+
expect(calls).toHaveLength(1)
|
|
302
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
303
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
})
|
|
307
|
+
describe('mutations without trx', () => {
|
|
308
|
+
test('create', async () => {
|
|
309
|
+
const [client, calls] = createClient({
|
|
310
|
+
mut: {
|
|
311
|
+
ok: true,
|
|
312
|
+
},
|
|
313
|
+
})
|
|
314
|
+
const createAuthor = qb.create('Author', {
|
|
315
|
+
data: {
|
|
316
|
+
name: 'John',
|
|
317
|
+
email: 'xx@localhost',
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
const result = await client.mutate(createAuthor)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
expect(result.ok).toBe(true)
|
|
324
|
+
expect(calls).toHaveLength(1)
|
|
325
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
326
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
test('mutation with a node', async () => {
|
|
330
|
+
const [client, calls] = createClient({
|
|
331
|
+
mut: {
|
|
332
|
+
ok: true,
|
|
333
|
+
node: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
const result = await client.mutate(qb.create('Author', {
|
|
337
|
+
data: {
|
|
338
|
+
name: 'John',
|
|
339
|
+
email: 'xx@localhost',
|
|
340
|
+
},
|
|
341
|
+
}, it => it.$('id')))
|
|
342
|
+
expect(result.ok).toBe(true)
|
|
343
|
+
expect(result.node?.id).toBe('ca7a9b84-efbb-435d-a063-da11f205335a')
|
|
344
|
+
expect(calls).toHaveLength(1)
|
|
345
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
346
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
test('update', async () => {
|
|
350
|
+
const [client, calls] = createClient({
|
|
351
|
+
mut: {
|
|
352
|
+
ok: true,
|
|
353
|
+
},
|
|
354
|
+
})
|
|
355
|
+
await client.mutate(qb.update('Author', {
|
|
356
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
357
|
+
data: {
|
|
358
|
+
name: 'John',
|
|
359
|
+
email: 'xx@localhost',
|
|
360
|
+
},
|
|
361
|
+
}))
|
|
362
|
+
expect(calls).toHaveLength(1)
|
|
363
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
364
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
test('delete', async () => {
|
|
368
|
+
const [client, calls] = createClient({
|
|
369
|
+
mut: {
|
|
370
|
+
ok: true,
|
|
371
|
+
},
|
|
372
|
+
})
|
|
373
|
+
await client.mutate(qb.delete('Author', {
|
|
374
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
375
|
+
}))
|
|
376
|
+
expect(calls).toHaveLength(1)
|
|
377
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
378
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
test('upsert', async () => {
|
|
382
|
+
const [client, calls] = createClient({
|
|
383
|
+
mut: {
|
|
384
|
+
ok: true,
|
|
385
|
+
},
|
|
386
|
+
})
|
|
387
|
+
await client.mutate(qb.upsert('Author', {
|
|
388
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
389
|
+
create: {
|
|
390
|
+
name: 'John',
|
|
391
|
+
email: 'xx@localhost',
|
|
392
|
+
},
|
|
393
|
+
update: {
|
|
394
|
+
name: 'John',
|
|
395
|
+
email: 'xx@localhost',
|
|
396
|
+
},
|
|
397
|
+
}))
|
|
398
|
+
expect(calls).toHaveLength(1)
|
|
399
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
400
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
test('multiple mutations as array', async () => {
|
|
404
|
+
const [client, calls] = createClient({
|
|
405
|
+
mut_0: {
|
|
406
|
+
ok: true,
|
|
407
|
+
},
|
|
408
|
+
mut_1: {
|
|
409
|
+
ok: true,
|
|
410
|
+
},
|
|
411
|
+
})
|
|
412
|
+
const result = await client.mutate([
|
|
413
|
+
qb.create('Author', {
|
|
414
|
+
data: {
|
|
415
|
+
name: 'John',
|
|
416
|
+
email: 'xx@localhost',
|
|
417
|
+
},
|
|
418
|
+
}),
|
|
419
|
+
qb.create('Author', {
|
|
420
|
+
data: {
|
|
421
|
+
name: 'John',
|
|
422
|
+
email: 'xx@localhost',
|
|
423
|
+
},
|
|
424
|
+
}),
|
|
425
|
+
])
|
|
426
|
+
expect(result).toHaveLength(2)
|
|
427
|
+
expect(result[0].ok).toBe(true)
|
|
428
|
+
expect(result[1].ok).toBe(true)
|
|
429
|
+
expect(calls).toHaveLength(1)
|
|
430
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
431
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
test('multiple named mutations', async () => {
|
|
435
|
+
const [client, calls] = createClient({
|
|
436
|
+
createAuthor: {
|
|
437
|
+
ok: true,
|
|
438
|
+
},
|
|
439
|
+
createPost: {
|
|
440
|
+
ok: true,
|
|
441
|
+
},
|
|
442
|
+
})
|
|
443
|
+
const result = await client.mutate({
|
|
444
|
+
createAuthor: qb.create('Author', {
|
|
445
|
+
data: {
|
|
446
|
+
name: 'John',
|
|
447
|
+
email: 'xx@localhost',
|
|
448
|
+
},
|
|
449
|
+
}),
|
|
450
|
+
createPost: qb.create('Post', {
|
|
451
|
+
data: {
|
|
452
|
+
publishedAt: 'now',
|
|
453
|
+
},
|
|
454
|
+
}),
|
|
455
|
+
})
|
|
456
|
+
expect(result.createAuthor.ok).toBe(true)
|
|
457
|
+
expect(result.createPost.ok).toBe(true)
|
|
458
|
+
expect(calls).toHaveLength(1)
|
|
459
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
460
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
test('mutation and query combo', async () => {
|
|
464
|
+
const [client, calls] = createClient({
|
|
465
|
+
createPost: {
|
|
466
|
+
ok: true,
|
|
467
|
+
},
|
|
468
|
+
post: {
|
|
469
|
+
value: {
|
|
470
|
+
id: 'ca7a9b84-efbb-435d-a063-da11f205335a',
|
|
471
|
+
publishedAt: 'now',
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
const result = await client.mutate({
|
|
477
|
+
createPost: qb.create('Post', {
|
|
478
|
+
data: {
|
|
479
|
+
publishedAt: 'now',
|
|
480
|
+
},
|
|
481
|
+
}),
|
|
482
|
+
post: qb.get('Post', {
|
|
483
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
484
|
+
}, it => it.$$()),
|
|
485
|
+
})
|
|
486
|
+
expect(result.createPost.ok).toBe(true)
|
|
487
|
+
expect(result.post?.publishedAt).toBe('now')
|
|
488
|
+
|
|
489
|
+
expect(calls).toHaveLength(1)
|
|
490
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
491
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
test('update locale relation', async () => {
|
|
495
|
+
const [client, calls] = createClient({
|
|
496
|
+
mut: {
|
|
497
|
+
ok: true,
|
|
498
|
+
},
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
const result = await client.mutate(qb.update('Post', {
|
|
502
|
+
by: { id: 'ca7a9b84-efbb-435d-a063-da11f205335a' },
|
|
503
|
+
data: {
|
|
504
|
+
publishedAt: 'now',
|
|
505
|
+
locales: [{
|
|
506
|
+
update: {
|
|
507
|
+
by: { locale: { code: 'cs' } },
|
|
508
|
+
data: {
|
|
509
|
+
title: 'cs title',
|
|
510
|
+
},
|
|
511
|
+
},
|
|
512
|
+
}],
|
|
513
|
+
},
|
|
514
|
+
}))
|
|
515
|
+
expect(result.ok).toBe(true)
|
|
516
|
+
expect(calls).toHaveLength(1)
|
|
517
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
518
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
})
|