@platformatic/sql-graphql 0.46.1 → 0.46.2
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/package.json +4 -4
- package/test/array.test.js +0 -372
- package/test/camelcase.test.js +0 -312
- package/test/composite.test.js +0 -474
- package/test/count.test.js +0 -126
- package/test/created_updated_at.test.js +0 -517
- package/test/datatypes.test.js +0 -803
- package/test/enum.test.js +0 -225
- package/test/federation.test.js +0 -312
- package/test/fix-428.test.js +0 -172
- package/test/helper.js +0 -169
- package/test/hooks.test.js +0 -660
- package/test/ignore.test.js +0 -289
- package/test/insert.test.js +0 -181
- package/test/inserted_updated_at.test.js +0 -533
- package/test/nested.test.js +0 -1269
- package/test/no-modification-of-entity.test.js +0 -113
- package/test/or.test.js +0 -302
- package/test/order_by.test.js +0 -397
- package/test/relations.test.js +0 -785
- package/test/schema.test.js +0 -277
- package/test/simple.test.js +0 -959
- package/test/special-chars.test.js +0 -47
- package/test/sqlite.test.js +0 -274
- package/test/subscription.test.js +0 -336
- package/test/types/errors.test-d.ts +0 -15
- package/test/types/index.test-d.ts +0 -32
- package/test/where.test.js +0 -1102
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test } = require('tap')
|
|
4
|
-
const sqlGraphQL = require('..')
|
|
5
|
-
const sqlMapper = require('@platformatic/sql-mapper')
|
|
6
|
-
const fastify = require('fastify')
|
|
7
|
-
const { clear, connInfo, isSQLite, isMysql } = require('./helper')
|
|
8
|
-
|
|
9
|
-
async function createBasicPages (db, sql) {
|
|
10
|
-
if (isSQLite) {
|
|
11
|
-
await db.query(sql`CREATE TABLE pages (
|
|
12
|
-
id INTEGER PRIMARY KEY,
|
|
13
|
-
title VARCHAR(42)
|
|
14
|
-
);`)
|
|
15
|
-
} else {
|
|
16
|
-
await db.query(sql`CREATE TABLE pages (
|
|
17
|
-
id SERIAL PRIMARY KEY,
|
|
18
|
-
title VARCHAR(42)
|
|
19
|
-
);`)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
test('no modification of entity', async ({ teardown, equal, pass }) => {
|
|
24
|
-
const app = fastify()
|
|
25
|
-
app.register(sqlMapper, {
|
|
26
|
-
...connInfo,
|
|
27
|
-
async onDatabaseLoad (db, sql) {
|
|
28
|
-
pass('onDatabaseLoad called')
|
|
29
|
-
|
|
30
|
-
await clear(db, sql)
|
|
31
|
-
await createBasicPages(db, sql)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
app.register(sqlGraphQL)
|
|
35
|
-
teardown(app.close.bind(app))
|
|
36
|
-
|
|
37
|
-
await app.ready()
|
|
38
|
-
|
|
39
|
-
equal(app.platformatic.entities.page.type, undefined, 'no type in entity')
|
|
40
|
-
|
|
41
|
-
for (const field of Object.values(app.platformatic.entities.page.fields)) {
|
|
42
|
-
equal(field.type, undefined, `no type in field ${field.camelcase}`)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('no modification of entity with nested data', async ({ pass, teardown, same, equal }) => {
|
|
47
|
-
const app = fastify()
|
|
48
|
-
app.register(sqlMapper, {
|
|
49
|
-
...connInfo,
|
|
50
|
-
async onDatabaseLoad (db, sql) {
|
|
51
|
-
pass('onDatabaseLoad called')
|
|
52
|
-
|
|
53
|
-
await clear(db, sql)
|
|
54
|
-
|
|
55
|
-
if (isMysql) {
|
|
56
|
-
await db.query(sql`
|
|
57
|
-
CREATE TABLE categories (
|
|
58
|
-
id SERIAL PRIMARY KEY,
|
|
59
|
-
name VARCHAR(255)
|
|
60
|
-
);
|
|
61
|
-
CREATE TABLE pages (
|
|
62
|
-
id SERIAL PRIMARY KEY,
|
|
63
|
-
title VARCHAR(42),
|
|
64
|
-
category_id BIGINT UNSIGNED,
|
|
65
|
-
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
|
|
66
|
-
);
|
|
67
|
-
`)
|
|
68
|
-
} else if (isSQLite) {
|
|
69
|
-
await db.query(sql`
|
|
70
|
-
CREATE TABLE categories (
|
|
71
|
-
id INTEGER PRIMARY KEY,
|
|
72
|
-
name VARCHAR(42)
|
|
73
|
-
);
|
|
74
|
-
`)
|
|
75
|
-
await db.query(sql`
|
|
76
|
-
CREATE TABLE pages (
|
|
77
|
-
id INTEGER PRIMARY KEY,
|
|
78
|
-
title VARCHAR(42),
|
|
79
|
-
category_id INTEGER REFERENCES categories(id)
|
|
80
|
-
);
|
|
81
|
-
`)
|
|
82
|
-
} else {
|
|
83
|
-
await db.query(sql`
|
|
84
|
-
CREATE TABLE categories (
|
|
85
|
-
id SERIAL PRIMARY KEY,
|
|
86
|
-
name VARCHAR(42)
|
|
87
|
-
);
|
|
88
|
-
CREATE TABLE pages (
|
|
89
|
-
id SERIAL PRIMARY KEY,
|
|
90
|
-
title VARCHAR(42),
|
|
91
|
-
category_id INTEGER REFERENCES categories(id)
|
|
92
|
-
);
|
|
93
|
-
`)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
app.register(sqlGraphQL)
|
|
98
|
-
teardown(app.close.bind(app))
|
|
99
|
-
|
|
100
|
-
await app.ready()
|
|
101
|
-
|
|
102
|
-
equal(app.platformatic.entities.page.type, undefined, 'no type in entity')
|
|
103
|
-
|
|
104
|
-
for (const field of Object.values(app.platformatic.entities.page.fields)) {
|
|
105
|
-
equal(field.type, undefined, `no type in field ${field.camelcase}`)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
equal(app.platformatic.entities.category.type, undefined, 'no type in entity')
|
|
109
|
-
|
|
110
|
-
for (const field of Object.values(app.platformatic.entities.category.fields)) {
|
|
111
|
-
equal(field.type, undefined, `no type in field ${field.camelcase}`)
|
|
112
|
-
}
|
|
113
|
-
})
|
package/test/or.test.js
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test } = require('tap')
|
|
4
|
-
const sqlGraphQL = require('..')
|
|
5
|
-
const sqlMapper = require('@platformatic/sql-mapper')
|
|
6
|
-
const fastify = require('fastify')
|
|
7
|
-
const { clear, connInfo, isSQLite } = require('./helper')
|
|
8
|
-
|
|
9
|
-
test('list', async ({ pass, teardown, same, equal }) => {
|
|
10
|
-
const app = fastify()
|
|
11
|
-
app.register(sqlMapper, {
|
|
12
|
-
...connInfo,
|
|
13
|
-
async onDatabaseLoad (db, sql) {
|
|
14
|
-
pass('onDatabaseLoad called')
|
|
15
|
-
|
|
16
|
-
await clear(db, sql)
|
|
17
|
-
|
|
18
|
-
if (isSQLite) {
|
|
19
|
-
await db.query(sql`CREATE TABLE posts (
|
|
20
|
-
id INTEGER PRIMARY KEY,
|
|
21
|
-
title VARCHAR(42),
|
|
22
|
-
long_text TEXT,
|
|
23
|
-
counter INTEGER
|
|
24
|
-
);`)
|
|
25
|
-
} else {
|
|
26
|
-
await db.query(sql`CREATE TABLE posts (
|
|
27
|
-
id SERIAL PRIMARY KEY,
|
|
28
|
-
title VARCHAR(42),
|
|
29
|
-
long_text TEXT,
|
|
30
|
-
counter INTEGER
|
|
31
|
-
);`)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
app.register(sqlGraphQL)
|
|
36
|
-
teardown(app.close.bind(app))
|
|
37
|
-
|
|
38
|
-
await app.ready()
|
|
39
|
-
|
|
40
|
-
const posts = [{
|
|
41
|
-
title: 'Dog',
|
|
42
|
-
longText: 'Foo',
|
|
43
|
-
counter: 10
|
|
44
|
-
}, {
|
|
45
|
-
title: 'Cat',
|
|
46
|
-
longText: 'Bar',
|
|
47
|
-
counter: 20
|
|
48
|
-
}, {
|
|
49
|
-
title: 'Mouse',
|
|
50
|
-
longText: 'Baz',
|
|
51
|
-
counter: 30
|
|
52
|
-
}, {
|
|
53
|
-
title: 'Duck',
|
|
54
|
-
longText: 'A duck tale',
|
|
55
|
-
counter: 40
|
|
56
|
-
}]
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
const res = await app.inject({
|
|
60
|
-
method: 'POST',
|
|
61
|
-
url: '/graphql',
|
|
62
|
-
body: {
|
|
63
|
-
query: `
|
|
64
|
-
mutation batch($inputs : [PostInput]!) {
|
|
65
|
-
insertPosts(inputs: $inputs) {
|
|
66
|
-
id
|
|
67
|
-
title
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
`,
|
|
71
|
-
variables: {
|
|
72
|
-
inputs: posts
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
const res = await app.inject({
|
|
81
|
-
method: 'POST',
|
|
82
|
-
url: '/graphql',
|
|
83
|
-
body: {
|
|
84
|
-
query: `
|
|
85
|
-
query {
|
|
86
|
-
posts(where: { or: [ { title: { eq: "Dog" } }, { title: { eq: "Cat" } } ] }) {
|
|
87
|
-
id
|
|
88
|
-
title
|
|
89
|
-
longText
|
|
90
|
-
counter
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
`
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
97
|
-
same(res.json(), {
|
|
98
|
-
data: {
|
|
99
|
-
posts: [
|
|
100
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
101
|
-
{ id: '2', title: 'Cat', longText: 'Bar', counter: 20 }
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
}, 'posts response')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
const res = await app.inject({
|
|
109
|
-
method: 'POST',
|
|
110
|
-
url: '/graphql',
|
|
111
|
-
body: {
|
|
112
|
-
query: `
|
|
113
|
-
query {
|
|
114
|
-
posts(where: { id: { eq: 1 }, or: [ { title: { eq: "Dog" } }, { title: { eq: "Cat" } } ] }) {
|
|
115
|
-
id
|
|
116
|
-
title
|
|
117
|
-
longText
|
|
118
|
-
counter
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
`
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
125
|
-
same(res.json(), {
|
|
126
|
-
data: {
|
|
127
|
-
posts: [
|
|
128
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 }
|
|
129
|
-
]
|
|
130
|
-
}
|
|
131
|
-
}, 'posts response')
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
const res = await app.inject({
|
|
136
|
-
method: 'POST',
|
|
137
|
-
url: '/graphql',
|
|
138
|
-
body: {
|
|
139
|
-
query: `
|
|
140
|
-
query {
|
|
141
|
-
posts(where: { or: [ { counter: { eq: 10 } }, { counter: { eq: 20 } } ] }) {
|
|
142
|
-
id
|
|
143
|
-
title
|
|
144
|
-
longText
|
|
145
|
-
counter
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
`
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
152
|
-
same(res.json(), {
|
|
153
|
-
data: {
|
|
154
|
-
posts: [
|
|
155
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
156
|
-
{ id: '2', title: 'Cat', longText: 'Bar', counter: 20 }
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
}, 'posts response')
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
{
|
|
163
|
-
const res = await app.inject({
|
|
164
|
-
method: 'POST',
|
|
165
|
-
url: '/graphql',
|
|
166
|
-
body: {
|
|
167
|
-
query: `
|
|
168
|
-
query {
|
|
169
|
-
posts(where: { or: [ { counter: { eq: 10 } }, { counter: { gte: 30 } } ] }) {
|
|
170
|
-
id
|
|
171
|
-
title
|
|
172
|
-
longText
|
|
173
|
-
counter
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
`
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
180
|
-
same(res.json(), {
|
|
181
|
-
data: {
|
|
182
|
-
posts: [
|
|
183
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
184
|
-
{ id: '3', title: 'Mouse', longText: 'Baz', counter: 30 },
|
|
185
|
-
{ id: '4', title: 'Duck', longText: 'A duck tale', counter: 40 }
|
|
186
|
-
]
|
|
187
|
-
}
|
|
188
|
-
}, 'posts response')
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
{
|
|
192
|
-
const res = await app.inject({
|
|
193
|
-
method: 'POST',
|
|
194
|
-
url: '/graphql',
|
|
195
|
-
body: {
|
|
196
|
-
query: `
|
|
197
|
-
query {
|
|
198
|
-
posts(where: { or: [ { title: { eq: "Dog" } }, { title: { eq: "Duck" } } ] }) {
|
|
199
|
-
id
|
|
200
|
-
title
|
|
201
|
-
longText
|
|
202
|
-
counter
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
`
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
209
|
-
same(res.json(), {
|
|
210
|
-
data: {
|
|
211
|
-
posts: [
|
|
212
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
213
|
-
{ id: '4', title: 'Duck', longText: 'A duck tale', counter: 40 }
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
}, 'posts response')
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
const res = await app.inject({
|
|
221
|
-
method: 'POST',
|
|
222
|
-
url: '/graphql',
|
|
223
|
-
body: {
|
|
224
|
-
query: `
|
|
225
|
-
query {
|
|
226
|
-
posts(where: { or: [ { title: { eq: "Dog" } }, { longText: { eq: "Baz" } } ] }) {
|
|
227
|
-
id
|
|
228
|
-
title
|
|
229
|
-
longText
|
|
230
|
-
counter
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
`
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
237
|
-
same(res.json(), {
|
|
238
|
-
data: {
|
|
239
|
-
posts: [
|
|
240
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
241
|
-
{ id: '3', title: 'Mouse', longText: 'Baz', counter: 30 }
|
|
242
|
-
]
|
|
243
|
-
}
|
|
244
|
-
}, 'posts response')
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
{
|
|
248
|
-
const res = await app.inject({
|
|
249
|
-
method: 'POST',
|
|
250
|
-
url: '/graphql',
|
|
251
|
-
body: {
|
|
252
|
-
query: `
|
|
253
|
-
query {
|
|
254
|
-
posts(where: { counter: { in: [10, 20] }, or: [ { title: { eq: "Dog" } }, { longText: { eq: "Baz" } } ] }) {
|
|
255
|
-
id
|
|
256
|
-
title
|
|
257
|
-
longText
|
|
258
|
-
counter
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
`
|
|
262
|
-
}
|
|
263
|
-
})
|
|
264
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
265
|
-
same(res.json(), {
|
|
266
|
-
data: {
|
|
267
|
-
posts: [
|
|
268
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 }
|
|
269
|
-
]
|
|
270
|
-
}
|
|
271
|
-
}, 'posts response')
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
{
|
|
275
|
-
const res = await app.inject({
|
|
276
|
-
method: 'POST',
|
|
277
|
-
url: '/graphql',
|
|
278
|
-
body: {
|
|
279
|
-
query: `
|
|
280
|
-
query {
|
|
281
|
-
posts(where: { or: [ { counter: { in: [10, 20] } }, { counter: { in: [20, 30] } } ] }) {
|
|
282
|
-
id
|
|
283
|
-
title
|
|
284
|
-
longText
|
|
285
|
-
counter
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
`
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
equal(res.statusCode, 200, 'posts status code')
|
|
292
|
-
same(res.json(), {
|
|
293
|
-
data: {
|
|
294
|
-
posts: [
|
|
295
|
-
{ id: '1', title: 'Dog', longText: 'Foo', counter: 10 },
|
|
296
|
-
{ id: '2', title: 'Cat', longText: 'Bar', counter: 20 },
|
|
297
|
-
{ id: '3', title: 'Mouse', longText: 'Baz', counter: 30 }
|
|
298
|
-
]
|
|
299
|
-
}
|
|
300
|
-
}, 'posts response')
|
|
301
|
-
}
|
|
302
|
-
})
|