@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.
@@ -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
- const getBy = camelcase(
111
- [
112
- 'get',
113
- singular,
114
- ...primaryKeys
115
- .map((key, i) => {
116
- if (i === 0) {
117
- return ['by', key]
118
- }
119
- return ['and', key]
120
- })
121
- .flat()
122
- ].join('_')
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
- queryTopFields[getBy] = {
176
- type,
177
- args: {
178
- ...primaryKeys.reduce((acc, primaryKey) => {
179
- acc[primaryKey] = { type: new GraphQLNonNull(fields[primaryKey].type) }
180
- return acc
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
- loaders.Query[getBy] = {
185
- loader (queries, ctx) {
186
- const keys = []
187
- for (const query of queries) {
188
- const pairs = []
189
- for (const key of primaryKeys) {
190
- pairs.push({ key, value: query.params[key] })
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.push(pairs)
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
- const save = camelcase(['save', singular])
283
+ // Views are read-only: skip all mutations
284
+ if (!entity.isView) {
285
+ const save = camelcase(['save', singular])
279
286
 
280
- mutationTopFields[save] = {
281
- type,
282
- args: {
283
- input: { type: new GraphQLNonNull(inputType) }
287
+ mutationTopFields[save] = {
288
+ type,
289
+ args: {
290
+ input: { type: new GraphQLNonNull(inputType) }
291
+ }
284
292
  }
285
- }
286
293
 
287
- resolvers.Mutation[save] = async (_, { input }, ctx, info) => {
288
- const fields = fromSelectionSet(info.fieldNodes[0].selectionSet)
289
- return entity.save({ input, ctx, fields: [...fields, ...relationalFields] })
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
- const insert = camelcase(['insert', plural])
299
+ const insert = camelcase(['insert', plural])
293
300
 
294
- mutationTopFields[insert] = {
295
- type: new GraphQLList(type),
296
- args: {
297
- inputs: { type: new GraphQLNonNull(new GraphQLList(inputType)) }
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
- resolvers.Mutation[insert] = (_, { inputs }, ctx, info) => {
302
- const fields = fromSelectionSet(info.fieldNodes[0].selectionSet)
303
- return entity.insert({ inputs, ctx, fields: [...fields, ...relationalFields] })
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
- const deleteKey = camelcase(['delete', plural])
307
- mutationTopFields[deleteKey] = {
308
- type: new GraphQLList(type),
309
- args: {
310
- where: { type: whereArgType }
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
- resolvers.Mutation[deleteKey] = (_, args, ctx, info) => {
315
- const fields = info.fieldNodes[0].selectionSet.selections.map(s => s.name.value)
316
- return entity.delete({ ...args, fields: [...fields, ...relationalFields], ctx })
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
- federationReplacements.push({
320
- find: new RegExp(`type ${entityName}`),
321
- replace: `type ${entityName} @key(fields: "${primaryKeys}")`
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
- if (federationMetadata) {
325
- loaders[entityName] = loaders[entityName] || {}
326
- loaders[entityName].__resolveReference = {
327
- loader (queries, ctx) {
328
- const keys = []
329
- for (const { obj } of queries) {
330
- const pairs = []
331
- for (const key of primaryKeys) {
332
- pairs.push({ key, value: obj[key] })
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.push(pairs)
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.0",
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/sql-events": "3.52.0",
31
- "@platformatic/sql-mapper": "3.52.0",
32
- "@platformatic/telemetry": "3.52.0"
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.0"
44
+ "@platformatic/foundation": "3.52.2"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=22.19.0"