@platformatic/sql-graphql 0.0.23
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/.nyc_output/0681b2b7-587a-40f2-8242-257bc4c72456.json +1 -0
- package/.nyc_output/191054d4-6a1e-4a1b-87bb-f801ed78a223.json +1 -0
- package/.nyc_output/22ead0f6-e5a6-4647-a2ea-db2f42498081.json +1 -0
- package/.nyc_output/4e847e26-05cd-4063-9277-48aff86d6822.json +1 -0
- package/.nyc_output/5acfd416-02d1-497b-8dbd-69c0af167c62.json +1 -0
- package/.nyc_output/5ec04f76-9bcb-475d-b79e-f9304cc0026c.json +1 -0
- package/.nyc_output/5f3bb47a-0d2d-440a-a466-8ffa9ab3efaa.json +1 -0
- package/.nyc_output/71c2bd84-9a72-4e86-83c6-d587ce525fe4.json +1 -0
- package/.nyc_output/74cc1dab-7479-48e7-80b0-c97351d8856e.json +1 -0
- package/.nyc_output/9f5d12ba-bc3d-461c-a0e2-2a95d2020c19.json +1 -0
- package/.nyc_output/ac343b71-6f76-421c-a287-46d19bb48f89.json +1 -0
- package/.nyc_output/c1c0eecb-63a0-4258-81b6-50e7488bd67c.json +1 -0
- package/.nyc_output/c201a1cd-3105-4d18-bbbb-8d7fa674d439.json +1 -0
- package/.nyc_output/d6da0270-e9ed-41e2-bbf3-9262d1df683c.json +1 -0
- package/.nyc_output/processinfo/0681b2b7-587a-40f2-8242-257bc4c72456.json +1 -0
- package/.nyc_output/processinfo/191054d4-6a1e-4a1b-87bb-f801ed78a223.json +1 -0
- package/.nyc_output/processinfo/22ead0f6-e5a6-4647-a2ea-db2f42498081.json +1 -0
- package/.nyc_output/processinfo/4e847e26-05cd-4063-9277-48aff86d6822.json +1 -0
- package/.nyc_output/processinfo/5acfd416-02d1-497b-8dbd-69c0af167c62.json +1 -0
- package/.nyc_output/processinfo/5ec04f76-9bcb-475d-b79e-f9304cc0026c.json +1 -0
- package/.nyc_output/processinfo/5f3bb47a-0d2d-440a-a466-8ffa9ab3efaa.json +1 -0
- package/.nyc_output/processinfo/71c2bd84-9a72-4e86-83c6-d587ce525fe4.json +1 -0
- package/.nyc_output/processinfo/74cc1dab-7479-48e7-80b0-c97351d8856e.json +1 -0
- package/.nyc_output/processinfo/9f5d12ba-bc3d-461c-a0e2-2a95d2020c19.json +1 -0
- package/.nyc_output/processinfo/ac343b71-6f76-421c-a287-46d19bb48f89.json +1 -0
- package/.nyc_output/processinfo/c1c0eecb-63a0-4258-81b6-50e7488bd67c.json +1 -0
- package/.nyc_output/processinfo/c201a1cd-3105-4d18-bbbb-8d7fa674d439.json +1 -0
- package/.nyc_output/processinfo/d6da0270-e9ed-41e2-bbf3-9262d1df683c.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.taprc +1 -0
- package/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +13 -0
- package/index.d.ts +40 -0
- package/index.js +117 -0
- package/lib/entity-to-type.js +248 -0
- package/lib/relationship.js +67 -0
- package/lib/utils.js +77 -0
- package/package.json +44 -0
- package/test/datatypes.test.js +708 -0
- package/test/federation.test.js +312 -0
- package/test/helper.js +70 -0
- package/test/hooks.test.js +660 -0
- package/test/ignore.test.js +117 -0
- package/test/insert.test.js +181 -0
- package/test/inserted_updated_at.test.js +517 -0
- package/test/nested.test.js +862 -0
- package/test/no-modification-of-entity.test.js +113 -0
- package/test/order_by.test.js +397 -0
- package/test/relations.test.js +60 -0
- package/test/simple.test.js +708 -0
- package/test/sqlite.test.js +276 -0
- package/test/types/index.test-d.ts +33 -0
- package/test/where.test.js +814 -0
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
})
|