@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
package/test/ignore.test.js
DELETED
|
@@ -1,289 +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
|
-
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
|
-
await db.query(sql`CREATE TABLE categories (
|
|
16
|
-
id INTEGER PRIMARY KEY,
|
|
17
|
-
name VARCHAR(42)
|
|
18
|
-
);`)
|
|
19
|
-
} else {
|
|
20
|
-
await db.query(sql`CREATE TABLE pages (
|
|
21
|
-
id SERIAL PRIMARY KEY,
|
|
22
|
-
title VARCHAR(42)
|
|
23
|
-
);`)
|
|
24
|
-
await db.query(sql`CREATE TABLE categories (
|
|
25
|
-
id SERIAL PRIMARY KEY,
|
|
26
|
-
name VARCHAR(42)
|
|
27
|
-
);`)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
test('ignore a table', async ({ pass, teardown, equal }) => {
|
|
32
|
-
const app = fastify()
|
|
33
|
-
app.register(sqlMapper, {
|
|
34
|
-
...connInfo,
|
|
35
|
-
ignore: {
|
|
36
|
-
categories: true
|
|
37
|
-
},
|
|
38
|
-
async onDatabaseLoad (db, sql) {
|
|
39
|
-
pass('onDatabaseLoad called')
|
|
40
|
-
|
|
41
|
-
await clear(db, sql)
|
|
42
|
-
await createBasicPages(db, sql)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
app.register(sqlGraphQL)
|
|
46
|
-
teardown(app.close.bind(app))
|
|
47
|
-
|
|
48
|
-
await app.ready()
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
const res = await app.inject({
|
|
52
|
-
method: 'POST',
|
|
53
|
-
url: '/graphql',
|
|
54
|
-
body: {
|
|
55
|
-
query: `
|
|
56
|
-
query {
|
|
57
|
-
__schema {
|
|
58
|
-
types {
|
|
59
|
-
name
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
`
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
equal(res.statusCode, 200, 'introspection query status code')
|
|
67
|
-
const data = res.json().data
|
|
68
|
-
equal(data.__schema.types.find((t) => t.name === 'Category'), undefined, 'Category type is ignored')
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('ignore a column', async ({ pass, teardown, equal }) => {
|
|
73
|
-
const app = fastify()
|
|
74
|
-
app.register(sqlMapper, {
|
|
75
|
-
...connInfo,
|
|
76
|
-
ignore: {
|
|
77
|
-
categories: {
|
|
78
|
-
name: true
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
async onDatabaseLoad (db, sql) {
|
|
82
|
-
pass('onDatabaseLoad called')
|
|
83
|
-
|
|
84
|
-
await clear(db, sql)
|
|
85
|
-
await createBasicPages(db, sql)
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
app.register(sqlGraphQL)
|
|
89
|
-
teardown(app.close.bind(app))
|
|
90
|
-
|
|
91
|
-
await app.ready()
|
|
92
|
-
|
|
93
|
-
{
|
|
94
|
-
const res = await app.inject({
|
|
95
|
-
method: 'POST',
|
|
96
|
-
url: '/graphql',
|
|
97
|
-
body: {
|
|
98
|
-
query: `
|
|
99
|
-
query {
|
|
100
|
-
__schema {
|
|
101
|
-
types {
|
|
102
|
-
name
|
|
103
|
-
fields {
|
|
104
|
-
name
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
`
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
equal(res.statusCode, 200, 'introspection query status code')
|
|
113
|
-
const data = res.json().data
|
|
114
|
-
const Category = data.__schema.types.find((t) => t.name === 'Category')
|
|
115
|
-
equal(Category.fields.find((f) => f.name === 'name'), undefined, 'name column is ignored')
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
test('ignore a table via sql-graphql option', async ({ pass, teardown, equal }) => {
|
|
120
|
-
const app = fastify()
|
|
121
|
-
app.register(sqlMapper, {
|
|
122
|
-
...connInfo,
|
|
123
|
-
async onDatabaseLoad (db, sql) {
|
|
124
|
-
pass('onDatabaseLoad called')
|
|
125
|
-
|
|
126
|
-
await clear(db, sql)
|
|
127
|
-
await createBasicPages(db, sql)
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
app.register(sqlGraphQL, {
|
|
131
|
-
ignore: {
|
|
132
|
-
category: true
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
teardown(app.close.bind(app))
|
|
136
|
-
|
|
137
|
-
await app.ready()
|
|
138
|
-
|
|
139
|
-
{
|
|
140
|
-
const res = await app.inject({
|
|
141
|
-
method: 'POST',
|
|
142
|
-
url: '/graphql',
|
|
143
|
-
body: {
|
|
144
|
-
query: `
|
|
145
|
-
query {
|
|
146
|
-
__schema {
|
|
147
|
-
types {
|
|
148
|
-
name
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
`
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
equal(res.statusCode, 200, 'introspection query status code')
|
|
156
|
-
const data = res.json().data
|
|
157
|
-
equal(data.__schema.types.find((t) => t.name === 'Category'), undefined, 'Category type is ignored')
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('show a warning if there is no ignored entity', async ({ plan, pass, teardown }) => {
|
|
162
|
-
plan(2)
|
|
163
|
-
|
|
164
|
-
const app = fastify({
|
|
165
|
-
logger: {
|
|
166
|
-
info () {},
|
|
167
|
-
debug () {},
|
|
168
|
-
trace () {},
|
|
169
|
-
fatal () {},
|
|
170
|
-
error () {},
|
|
171
|
-
child () {
|
|
172
|
-
return this
|
|
173
|
-
},
|
|
174
|
-
warn (msg) {
|
|
175
|
-
if (msg === 'Ignored graphql entity "missingEntityPages" not found. Did you mean "page"?') {
|
|
176
|
-
pass('warning message is shown')
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
app.register(sqlMapper, {
|
|
183
|
-
...connInfo,
|
|
184
|
-
async onDatabaseLoad (db, sql) {
|
|
185
|
-
pass('onDatabaseLoad called')
|
|
186
|
-
|
|
187
|
-
await clear(db, sql)
|
|
188
|
-
await createBasicPages(db, sql)
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
app.register(sqlGraphQL, {
|
|
192
|
-
ignore: {
|
|
193
|
-
missingEntityPages: true
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
teardown(app.close.bind(app))
|
|
197
|
-
|
|
198
|
-
await app.ready()
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test('ignore a column via sql-graphql option', async ({ pass, teardown, equal }) => {
|
|
202
|
-
const app = fastify()
|
|
203
|
-
app.register(sqlMapper, {
|
|
204
|
-
...connInfo,
|
|
205
|
-
async onDatabaseLoad (db, sql) {
|
|
206
|
-
pass('onDatabaseLoad called')
|
|
207
|
-
|
|
208
|
-
await clear(db, sql)
|
|
209
|
-
await createBasicPages(db, sql)
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
app.register(sqlGraphQL, {
|
|
213
|
-
ignore: {
|
|
214
|
-
category: {
|
|
215
|
-
name: true
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
teardown(app.close.bind(app))
|
|
220
|
-
|
|
221
|
-
await app.ready()
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
const res = await app.inject({
|
|
225
|
-
method: 'POST',
|
|
226
|
-
url: '/graphql',
|
|
227
|
-
body: {
|
|
228
|
-
query: `
|
|
229
|
-
query {
|
|
230
|
-
__schema {
|
|
231
|
-
types {
|
|
232
|
-
name
|
|
233
|
-
fields {
|
|
234
|
-
name
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
`
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
equal(res.statusCode, 200, 'introspection query status code')
|
|
243
|
-
const data = res.json().data
|
|
244
|
-
const Category = data.__schema.types.find((t) => t.name === 'Category')
|
|
245
|
-
equal(Category.fields.find((f) => f.name === 'name'), undefined, 'name column is ignored')
|
|
246
|
-
}
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
test('show a warning if there is no ignored entity field', async ({ plan, pass, teardown }) => {
|
|
250
|
-
plan(2)
|
|
251
|
-
|
|
252
|
-
const app = fastify({
|
|
253
|
-
logger: {
|
|
254
|
-
info () {},
|
|
255
|
-
debug () {},
|
|
256
|
-
trace () {},
|
|
257
|
-
fatal () {},
|
|
258
|
-
error () {},
|
|
259
|
-
child () {
|
|
260
|
-
return this
|
|
261
|
-
},
|
|
262
|
-
warn (msg) {
|
|
263
|
-
if (msg === 'Ignored graphql field "missingFieldName" not found in entity "category". Did you mean "name"?') {
|
|
264
|
-
pass('warning message is shown')
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
app.register(sqlMapper, {
|
|
271
|
-
...connInfo,
|
|
272
|
-
async onDatabaseLoad (db, sql) {
|
|
273
|
-
pass('onDatabaseLoad called')
|
|
274
|
-
|
|
275
|
-
await clear(db, sql)
|
|
276
|
-
await createBasicPages(db, sql)
|
|
277
|
-
}
|
|
278
|
-
})
|
|
279
|
-
app.register(sqlGraphQL, {
|
|
280
|
-
ignore: {
|
|
281
|
-
category: {
|
|
282
|
-
missingFieldName: true
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
teardown(app.close.bind(app))
|
|
287
|
-
|
|
288
|
-
await app.ready()
|
|
289
|
-
})
|
package/test/insert.test.js
DELETED
|
@@ -1,181 +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, isPg } = require('./helper')
|
|
8
|
-
|
|
9
|
-
test('batch inserts', 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 pages (
|
|
20
|
-
id INTEGER PRIMARY KEY,
|
|
21
|
-
title VARCHAR(42)
|
|
22
|
-
);`)
|
|
23
|
-
} else {
|
|
24
|
-
await db.query(sql`CREATE TABLE pages (
|
|
25
|
-
id SERIAL PRIMARY KEY,
|
|
26
|
-
title VARCHAR(42)
|
|
27
|
-
);`)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
app.register(sqlGraphQL)
|
|
32
|
-
teardown(app.close.bind(app))
|
|
33
|
-
|
|
34
|
-
await app.ready()
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
const res = await app.inject({
|
|
38
|
-
method: 'POST',
|
|
39
|
-
url: '/graphql',
|
|
40
|
-
body: {
|
|
41
|
-
query: `
|
|
42
|
-
mutation batch($inputs : [PageInput]!) {
|
|
43
|
-
insertPages (inputs: $inputs) {
|
|
44
|
-
id
|
|
45
|
-
title
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`,
|
|
49
|
-
variables: {
|
|
50
|
-
inputs: [
|
|
51
|
-
{ title: 'Page 1' },
|
|
52
|
-
{ title: 'Page 2' },
|
|
53
|
-
{ title: 'Page 3' }
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
equal(res.statusCode, 200, 'savePage status code')
|
|
59
|
-
same(res.json(), {
|
|
60
|
-
data: {
|
|
61
|
-
insertPages: [
|
|
62
|
-
{ id: 1, title: 'Page 1' },
|
|
63
|
-
{ id: 2, title: 'Page 2' },
|
|
64
|
-
{ id: 3, title: 'Page 3' }
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
}, 'savePage response')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
const res = await app.inject({
|
|
72
|
-
method: 'POST',
|
|
73
|
-
url: '/graphql',
|
|
74
|
-
body: {
|
|
75
|
-
query: `
|
|
76
|
-
query {
|
|
77
|
-
pages {
|
|
78
|
-
id
|
|
79
|
-
title
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
`
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
equal(res.statusCode, 200, 'pages status code')
|
|
86
|
-
same(res.json(), {
|
|
87
|
-
data: {
|
|
88
|
-
pages: [
|
|
89
|
-
{ id: 1, title: 'Page 1' },
|
|
90
|
-
{ id: 2, title: 'Page 2' },
|
|
91
|
-
{ id: 3, title: 'Page 3' }
|
|
92
|
-
]
|
|
93
|
-
}
|
|
94
|
-
}, 'pages response')
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test('[PG] - batch inserts UUID', { skip: !isPg }, async ({ pass, teardown, same, equal, match }) => {
|
|
99
|
-
const app = fastify()
|
|
100
|
-
app.register(sqlMapper, {
|
|
101
|
-
...connInfo,
|
|
102
|
-
async onDatabaseLoad (db, sql) {
|
|
103
|
-
pass('onDatabaseLoad called')
|
|
104
|
-
|
|
105
|
-
await clear(db, sql)
|
|
106
|
-
|
|
107
|
-
await db.query(sql`
|
|
108
|
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
109
|
-
CREATE TABLE pages (
|
|
110
|
-
id uuid PRIMARY KEY default uuid_generate_v1(),
|
|
111
|
-
title VARCHAR(42)
|
|
112
|
-
);`)
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
app.register(sqlGraphQL)
|
|
116
|
-
teardown(app.close.bind(app))
|
|
117
|
-
|
|
118
|
-
await app.ready()
|
|
119
|
-
|
|
120
|
-
let ids
|
|
121
|
-
{
|
|
122
|
-
const res = await app.inject({
|
|
123
|
-
method: 'POST',
|
|
124
|
-
url: '/graphql',
|
|
125
|
-
body: {
|
|
126
|
-
query: `
|
|
127
|
-
mutation batch($inputs : [PageInput]!) {
|
|
128
|
-
insertPages (inputs: $inputs) {
|
|
129
|
-
id
|
|
130
|
-
title
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
`,
|
|
134
|
-
variables: {
|
|
135
|
-
inputs: [
|
|
136
|
-
{ title: 'Page 1' },
|
|
137
|
-
{ title: 'Page 2' },
|
|
138
|
-
{ title: 'Page 3' }
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
equal(res.statusCode, 200, 'savePage status code')
|
|
144
|
-
ids = res.json().data.insertPages
|
|
145
|
-
match(res.json(), {
|
|
146
|
-
data: {
|
|
147
|
-
insertPages: [
|
|
148
|
-
{ title: 'Page 1' },
|
|
149
|
-
{ title: 'Page 2' },
|
|
150
|
-
{ title: 'Page 3' }
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
}, 'insertPages response')
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
for (const { id, title } of ids) {
|
|
157
|
-
const res = await app.inject({
|
|
158
|
-
method: 'POST',
|
|
159
|
-
url: '/graphql',
|
|
160
|
-
body: {
|
|
161
|
-
query: `
|
|
162
|
-
query {
|
|
163
|
-
getPageById(id: "${id}") {
|
|
164
|
-
id
|
|
165
|
-
title
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
`
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
equal(res.statusCode, 200, 'getPageById status code')
|
|
172
|
-
same(res.json(), {
|
|
173
|
-
data: {
|
|
174
|
-
getPageById: {
|
|
175
|
-
id,
|
|
176
|
-
title
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}, 'getPageById response')
|
|
180
|
-
}
|
|
181
|
-
})
|