@platformatic/sql-graphql 3.52.0 → 3.52.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/lib/entity-to-type.js +91 -81
- package/package.json +5 -5
package/lib/entity-to-type.js
CHANGED
|
@@ -107,20 +107,23 @@ export function constructGraph (app, entity, opts, ignore) {
|
|
|
107
107
|
resolvers.Mutation = resolvers.Mutation || {}
|
|
108
108
|
loaders.Query = loaders.Query || {}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
let getBy
|
|
111
|
+
if (primaryKeys.length > 0) {
|
|
112
|
+
getBy = camelcase(
|
|
113
|
+
[
|
|
114
|
+
'get',
|
|
115
|
+
singular,
|
|
116
|
+
...primaryKeys
|
|
117
|
+
.map((key, i) => {
|
|
118
|
+
if (i === 0) {
|
|
119
|
+
return ['by', key]
|
|
120
|
+
}
|
|
121
|
+
return ['and', key]
|
|
122
|
+
})
|
|
123
|
+
.flat()
|
|
124
|
+
].join('_')
|
|
125
|
+
)
|
|
126
|
+
}
|
|
124
127
|
|
|
125
128
|
const whereFields = Object.keys(fields).reduce((acc, field) => {
|
|
126
129
|
let graphqlFields
|
|
@@ -172,29 +175,31 @@ export function constructGraph (app, entity, opts, ignore) {
|
|
|
172
175
|
}
|
|
173
176
|
})
|
|
174
177
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
acc
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
if (getBy) {
|
|
179
|
+
queryTopFields[getBy] = {
|
|
180
|
+
type,
|
|
181
|
+
args: {
|
|
182
|
+
...primaryKeys.reduce((acc, primaryKey) => {
|
|
183
|
+
acc[primaryKey] = { type: new GraphQLNonNull(fields[primaryKey].type) }
|
|
184
|
+
return acc
|
|
185
|
+
}, {})
|
|
186
|
+
}
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
loaders.Query[getBy] = {
|
|
189
|
+
loader (queries, ctx) {
|
|
190
|
+
const keys = []
|
|
191
|
+
for (const query of queries) {
|
|
192
|
+
const pairs = []
|
|
193
|
+
for (const key of primaryKeys) {
|
|
194
|
+
pairs.push({ key, value: query.params[key] })
|
|
195
|
+
}
|
|
196
|
+
keys.push(pairs)
|
|
191
197
|
}
|
|
192
|
-
keys
|
|
198
|
+
return loadMany(keys, queries, ctx)
|
|
199
|
+
},
|
|
200
|
+
opts: {
|
|
201
|
+
cache: false
|
|
193
202
|
}
|
|
194
|
-
return loadMany(keys, queries, ctx)
|
|
195
|
-
},
|
|
196
|
-
opts: {
|
|
197
|
-
cache: false
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
205
|
|
|
@@ -275,68 +280,73 @@ export function constructGraph (app, entity, opts, ignore) {
|
|
|
275
280
|
return { total }
|
|
276
281
|
}
|
|
277
282
|
|
|
278
|
-
|
|
283
|
+
// Views are read-only: skip all mutations
|
|
284
|
+
if (!entity.isView) {
|
|
285
|
+
const save = camelcase(['save', singular])
|
|
279
286
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
287
|
+
mutationTopFields[save] = {
|
|
288
|
+
type,
|
|
289
|
+
args: {
|
|
290
|
+
input: { type: new GraphQLNonNull(inputType) }
|
|
291
|
+
}
|
|
284
292
|
}
|
|
285
|
-
}
|
|
286
293
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
294
|
+
resolvers.Mutation[save] = async (_, { input }, ctx, info) => {
|
|
295
|
+
const fields = fromSelectionSet(info.fieldNodes[0].selectionSet)
|
|
296
|
+
return entity.save({ input, ctx, fields: [...fields, ...relationalFields] })
|
|
297
|
+
}
|
|
291
298
|
|
|
292
|
-
|
|
299
|
+
const insert = camelcase(['insert', plural])
|
|
293
300
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
301
|
+
mutationTopFields[insert] = {
|
|
302
|
+
type: new GraphQLList(type),
|
|
303
|
+
args: {
|
|
304
|
+
inputs: { type: new GraphQLNonNull(new GraphQLList(inputType)) }
|
|
305
|
+
}
|
|
298
306
|
}
|
|
299
|
-
}
|
|
300
307
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
resolvers.Mutation[insert] = (_, { inputs }, ctx, info) => {
|
|
309
|
+
const fields = fromSelectionSet(info.fieldNodes[0].selectionSet)
|
|
310
|
+
return entity.insert({ inputs, ctx, fields: [...fields, ...relationalFields] })
|
|
311
|
+
}
|
|
305
312
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
313
|
+
const deleteKey = camelcase(['delete', plural])
|
|
314
|
+
mutationTopFields[deleteKey] = {
|
|
315
|
+
type: new GraphQLList(type),
|
|
316
|
+
args: {
|
|
317
|
+
where: { type: whereArgType }
|
|
318
|
+
}
|
|
311
319
|
}
|
|
312
|
-
}
|
|
313
320
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
321
|
+
resolvers.Mutation[deleteKey] = (_, args, ctx, info) => {
|
|
322
|
+
const fields = info.fieldNodes[0].selectionSet.selections.map(s => s.name.value)
|
|
323
|
+
return entity.delete({ ...args, fields: [...fields, ...relationalFields], ctx })
|
|
324
|
+
}
|
|
317
325
|
}
|
|
318
326
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
if (primaryKeys.length > 0) {
|
|
328
|
+
federationReplacements.push({
|
|
329
|
+
find: new RegExp(`type ${entityName}`),
|
|
330
|
+
replace: `type ${entityName} @key(fields: "${primaryKeys}")`
|
|
331
|
+
})
|
|
323
332
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
+
if (federationMetadata) {
|
|
334
|
+
loaders[entityName] = loaders[entityName] || {}
|
|
335
|
+
loaders[entityName].__resolveReference = {
|
|
336
|
+
loader (queries, ctx) {
|
|
337
|
+
const keys = []
|
|
338
|
+
for (const { obj } of queries) {
|
|
339
|
+
const pairs = []
|
|
340
|
+
for (const key of primaryKeys) {
|
|
341
|
+
pairs.push({ key, value: obj[key] })
|
|
342
|
+
}
|
|
343
|
+
keys.push(pairs)
|
|
333
344
|
}
|
|
334
|
-
keys
|
|
345
|
+
return loadMany(keys, queries, ctx)
|
|
346
|
+
},
|
|
347
|
+
opts: {
|
|
348
|
+
cache: false
|
|
335
349
|
}
|
|
336
|
-
return loadMany(keys, queries, ctx)
|
|
337
|
-
},
|
|
338
|
-
opts: {
|
|
339
|
-
cache: false
|
|
340
350
|
}
|
|
341
351
|
}
|
|
342
352
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-graphql",
|
|
3
|
-
"version": "3.52.
|
|
3
|
+
"version": "3.52.2",
|
|
4
4
|
"description": "Map SQL dbs to GraphQL",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"typescript": "^5.5.4",
|
|
28
28
|
"why-is-node-running": "^2.2.2",
|
|
29
29
|
"ws": "^8.16.0",
|
|
30
|
-
"@platformatic/
|
|
31
|
-
"@platformatic/sql-
|
|
32
|
-
"@platformatic/
|
|
30
|
+
"@platformatic/telemetry": "3.52.2",
|
|
31
|
+
"@platformatic/sql-events": "3.52.2",
|
|
32
|
+
"@platformatic/sql-mapper": "3.52.2"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@fastify/error": "^4.0.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"graphql-type-json": "^0.3.2",
|
|
42
42
|
"inflected": "^2.1.0",
|
|
43
43
|
"mercurius": "^16.0.0",
|
|
44
|
-
"@platformatic/foundation": "3.52.
|
|
44
|
+
"@platformatic/foundation": "3.52.2"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=22.19.0"
|