@platformatic/sql-graphql 2.0.0-alpha.1 → 2.0.0-alpha.10

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.
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({ ts: true })
package/index.d.ts CHANGED
@@ -47,4 +47,3 @@ export module errors {
47
47
  export const UnsupportedKindError: (kind: string) => FastifyError
48
48
  export const ErrorPrintingGraphQLSchema: () => FastifyError
49
49
  }
50
-
package/index.js CHANGED
@@ -28,7 +28,7 @@ async function mapperToGraphql (app, opts) {
28
28
  resolvers,
29
29
  loaders,
30
30
  federationReplacements,
31
- federationMetadata: opts.federationMetadata
31
+ federationMetadata: opts.federationMetadata,
32
32
  }
33
33
  const metaMap = new Map()
34
34
 
@@ -36,7 +36,7 @@ async function mapperToGraphql (app, opts) {
36
36
  // no schema
37
37
  queryTopFields.hello = { type: graphql.GraphQLString }
38
38
  resolvers.Query = {
39
- hello: () => 'Hello Platformatic!'
39
+ hello: () => 'Hello Platformatic!',
40
40
  }
41
41
  } else {
42
42
  const entitiesNames = Object.values(mapper.entities)
@@ -96,13 +96,13 @@ async function mapperToGraphql (app, opts) {
96
96
 
97
97
  const query = new graphql.GraphQLObjectType({
98
98
  name: 'Query',
99
- fields: queryTopFields
99
+ fields: queryTopFields,
100
100
  })
101
101
 
102
102
  const mutation = Object.keys(mutationTopFields).length > 0
103
103
  ? new graphql.GraphQLObjectType({
104
104
  name: 'Mutation',
105
- fields: mutationTopFields
105
+ fields: mutationTopFields,
106
106
  })
107
107
  : null
108
108
 
@@ -130,7 +130,7 @@ async function mapperToGraphql (app, opts) {
130
130
 
131
131
  if (entitiesList.length > 0) {
132
132
  opts.subscription = {
133
- emitter: app.platformatic.mq
133
+ emitter: app.platformatic.mq,
134
134
  }
135
135
  // TODO support ignoring some of those
136
136
  subscription = setupSubscriptions(app, metaMap, resolvers, ignoreList)
@@ -184,7 +184,7 @@ async function mapperToGraphql (app, opts) {
184
184
  ...opts,
185
185
  schema: sdl,
186
186
  loaders,
187
- resolvers
187
+ resolvers,
188
188
  })
189
189
 
190
190
  if (app.openTelemetry) {
@@ -5,7 +5,7 @@ const camelcase = require('camelcase')
5
5
  const { findNearestString } = require('@platformatic/utils')
6
6
  const {
7
7
  sqlTypeToGraphQL,
8
- fromSelectionSet
8
+ fromSelectionSet,
9
9
  } = require('./utils')
10
10
  const errors = require('./errors')
11
11
 
@@ -13,13 +13,13 @@ const ascDesc = new graphql.GraphQLEnumType({
13
13
  name: 'OrderByDirection',
14
14
  values: {
15
15
  ASC: { value: 'ASC' },
16
- DESC: { value: 'DESC' }
17
- }
16
+ DESC: { value: 'DESC' },
17
+ },
18
18
  })
19
19
 
20
20
  const limitType = new graphql.GraphQLScalarType({
21
21
  name: 'LimitInt',
22
- description: 'Limit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown'
22
+ description: 'Limit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown',
23
23
  })
24
24
 
25
25
  function constructGraph (app, entity, opts, ignore) {
@@ -35,7 +35,7 @@ function constructGraph (app, entity, opts, ignore) {
35
35
  resolvers,
36
36
  federationReplacements,
37
37
  federationMetadata,
38
- loaders
38
+ loaders,
39
39
  } = opts
40
40
 
41
41
  const entityFieldsNames = Object.values(entity.fields)
@@ -104,7 +104,7 @@ function constructGraph (app, entity, opts, ignore) {
104
104
 
105
105
  const type = new graphql.GraphQLObjectType({
106
106
  name: entityName,
107
- fields
107
+ fields,
108
108
  })
109
109
 
110
110
  resolvers.Query = resolvers.Query || {}
@@ -131,7 +131,7 @@ function constructGraph (app, entity, opts, ignore) {
131
131
  lte: { type: fields[field].type },
132
132
  like: { type: fields[field].type },
133
133
  in: { type: new graphql.GraphQLList(fields[field].type) },
134
- nin: { type: new graphql.GraphQLList(fields[field].type) }
134
+ nin: { type: new graphql.GraphQLList(fields[field].type) },
135
135
  }
136
136
  } else {
137
137
  graphqlFields = {
@@ -139,14 +139,14 @@ function constructGraph (app, entity, opts, ignore) {
139
139
  all: { type: fields[field].type.ofType },
140
140
  contains: { type: new graphql.GraphQLList(fields[field].type) },
141
141
  contained: { type: new graphql.GraphQLList(fields[field].type) },
142
- overlaps: { type: new graphql.GraphQLList(fields[field].type) }
142
+ overlaps: { type: new graphql.GraphQLList(fields[field].type) },
143
143
  }
144
144
  }
145
145
  acc[field] = {
146
146
  type: new graphql.GraphQLInputObjectType({
147
147
  name: `${entityName}WhereArguments${field}`,
148
- fields: graphqlFields
149
- })
148
+ fields: graphqlFields,
149
+ }),
150
150
  }
151
151
  return acc
152
152
  }, {})
@@ -159,11 +159,11 @@ function constructGraph (app, entity, opts, ignore) {
159
159
  type: new graphql.GraphQLList(new graphql.GraphQLInputObjectType({
160
160
  name: `${entityName}WhereArgumentsOr`,
161
161
  fields: {
162
- ...whereFields
163
- }
164
- }))
165
- }
166
- }
162
+ ...whereFields,
163
+ },
164
+ })),
165
+ },
166
+ },
167
167
  })
168
168
 
169
169
  queryTopFields[getBy] = {
@@ -172,8 +172,8 @@ function constructGraph (app, entity, opts, ignore) {
172
172
  ...(primaryKeys.reduce((acc, primaryKey) => {
173
173
  acc[primaryKey] = { type: new graphql.GraphQLNonNull(fields[primaryKey].type) }
174
174
  return acc
175
- }, {}))
176
- }
175
+ }, {})),
176
+ },
177
177
  }
178
178
  loaders.Query[getBy] = {
179
179
  loader (queries, ctx) {
@@ -188,8 +188,8 @@ function constructGraph (app, entity, opts, ignore) {
188
188
  return loadMany(keys, queries, ctx)
189
189
  },
190
190
  opts: {
191
- cache: false
192
- }
191
+ cache: false,
192
+ },
193
193
  }
194
194
 
195
195
  const orderByFields = new graphql.GraphQLEnumType({
@@ -198,11 +198,11 @@ function constructGraph (app, entity, opts, ignore) {
198
198
  /* istanbul ignore else */
199
199
  if (!fields[field].isArray) {
200
200
  acc[field] = {
201
- value: field
201
+ value: field,
202
202
  }
203
203
  }
204
204
  return acc
205
- }, {})
205
+ }, {}),
206
206
  })
207
207
  queryTopFields[plural] = {
208
208
  type: new graphql.GraphQLList(type),
@@ -214,12 +214,12 @@ function constructGraph (app, entity, opts, ignore) {
214
214
  name: `${entityName}OrderByArguments`,
215
215
  fields: {
216
216
  field: { type: orderByFields },
217
- direction: { type: new graphql.GraphQLNonNull(ascDesc) }
218
- }
219
- }))
217
+ direction: { type: new graphql.GraphQLNonNull(ascDesc) },
218
+ },
219
+ })),
220
220
  },
221
- where: { type: whereArgType }
222
- }
221
+ where: { type: whereArgType },
222
+ },
223
223
  }
224
224
 
225
225
  resolvers.Query[plural] = (_, query, ctx, info) => {
@@ -239,7 +239,7 @@ function constructGraph (app, entity, opts, ignore) {
239
239
  acc[field] = meta
240
240
  }
241
241
  return acc
242
- }, {})
242
+ }, {}),
243
243
  })
244
244
 
245
245
  const count = camelcase(['count', plural])
@@ -247,15 +247,15 @@ function constructGraph (app, entity, opts, ignore) {
247
247
  const countType = new graphql.GraphQLObjectType({
248
248
  name: `${plural}Count`,
249
249
  fields: {
250
- total: { type: graphql.GraphQLInt }
251
- }
250
+ total: { type: graphql.GraphQLInt },
251
+ },
252
252
  })
253
253
 
254
254
  queryTopFields[count] = {
255
255
  type: countType,
256
256
  args: {
257
- where: { type: whereArgType }
258
- }
257
+ where: { type: whereArgType },
258
+ },
259
259
  }
260
260
 
261
261
  resolvers.Query[count] = async (_, query, ctx, info) => {
@@ -272,8 +272,8 @@ function constructGraph (app, entity, opts, ignore) {
272
272
  mutationTopFields[save] = {
273
273
  type,
274
274
  args: {
275
- input: { type: new graphql.GraphQLNonNull(inputType) }
276
- }
275
+ input: { type: new graphql.GraphQLNonNull(inputType) },
276
+ },
277
277
  }
278
278
 
279
279
  resolvers.Mutation[save] = async (_, { input }, ctx, info) => {
@@ -286,8 +286,8 @@ function constructGraph (app, entity, opts, ignore) {
286
286
  mutationTopFields[insert] = {
287
287
  type: new graphql.GraphQLList(type),
288
288
  args: {
289
- inputs: { type: new graphql.GraphQLNonNull(new graphql.GraphQLList(inputType)) }
290
- }
289
+ inputs: { type: new graphql.GraphQLNonNull(new graphql.GraphQLList(inputType)) },
290
+ },
291
291
  }
292
292
 
293
293
  resolvers.Mutation[insert] = (_, { inputs }, ctx, info) => {
@@ -299,8 +299,8 @@ function constructGraph (app, entity, opts, ignore) {
299
299
  mutationTopFields[deleteKey] = {
300
300
  type: new graphql.GraphQLList(type),
301
301
  args: {
302
- where: { type: whereArgType }
303
- }
302
+ where: { type: whereArgType },
303
+ },
304
304
  }
305
305
 
306
306
  resolvers.Mutation[deleteKey] = (_, args, ctx, info) => {
@@ -310,7 +310,7 @@ function constructGraph (app, entity, opts, ignore) {
310
310
 
311
311
  federationReplacements.push({
312
312
  find: new RegExp(`type ${entityName}`),
313
- replace: `type ${entityName} @key(fields: "${primaryKeys}")`
313
+ replace: `type ${entityName} @key(fields: "${primaryKeys}")`,
314
314
  })
315
315
 
316
316
  if (federationMetadata) {
@@ -328,8 +328,8 @@ function constructGraph (app, entity, opts, ignore) {
328
328
  return loadMany(keys, queries, ctx)
329
329
  },
330
330
  opts: {
331
- cache: false
332
- }
331
+ cache: false,
332
+ },
333
333
  }
334
334
  }
335
335
 
@@ -339,7 +339,7 @@ function constructGraph (app, entity, opts, ignore) {
339
339
  loadMany,
340
340
  getFields,
341
341
  relationalFields,
342
- fields
342
+ fields,
343
343
  }
344
344
 
345
345
  async function loadMany (keys, queries, ctx) {
@@ -357,7 +357,7 @@ function constructGraph (app, entity, opts, ignore) {
357
357
  acc[key].in.push(value)
358
358
  } else {
359
359
  acc[key] = {
360
- in: [value]
360
+ in: [value],
361
361
  }
362
362
  }
363
363
  return acc
@@ -369,7 +369,7 @@ function constructGraph (app, entity, opts, ignore) {
369
369
  where,
370
370
  fields,
371
371
  limit,
372
- ctx
372
+ ctx,
373
373
  })
374
374
 
375
375
  const matchedRaws = []
package/lib/errors.js CHANGED
@@ -7,5 +7,5 @@ const ERROR_PREFIX = 'PLT_SQL_GRAPHQL'
7
7
  module.exports = {
8
8
  UnableToGenerateGraphQLEnumTypeError: createError(`${ERROR_PREFIX}_UNABLE_GENERATE_GRAPHQL_ENUM_TYPE`, 'Unable to generate GraphQLEnumType'),
9
9
  UnsupportedKindError: createError(`${ERROR_PREFIX}_UNSUPPORTED_KIND`, 'Unsupported kind: %s'),
10
- ErrorPrintingGraphQLSchema: createError(`${ERROR_PREFIX}_ERROR_PRINTING_GRAPHQL_SCHEMA`, 'Error printing the GraphQL schema')
10
+ ErrorPrintingGraphQLSchema: createError(`${ERROR_PREFIX}_ERROR_PRINTING_GRAPHQL_SCHEMA`, 'Error printing the GraphQL schema'),
11
11
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  const camelcase = require('camelcase')
6
6
  const {
7
- fromSelectionSet
7
+ fromSelectionSet,
8
8
  } = require('./utils')
9
9
  const assert = require('assert')
10
10
 
@@ -49,8 +49,8 @@ module.exports = function establishRelations (app, relations, resolvers, loaders
49
49
  return foreign.loadMany(keys, queries, ctx)
50
50
  },
51
51
  opts: {
52
- cache: false
53
- }
52
+ cache: false,
53
+ },
54
54
  }
55
55
  }
56
56
  }
@@ -21,7 +21,7 @@ function setupSubscriptions (app, metaMap, resolvers, ignores) {
21
21
  const { type } = meta
22
22
  const saved = `${field.singularName}Saved`
23
23
  fields[saved] = {
24
- type
24
+ type,
25
25
  }
26
26
  resolvers.Subscription[saved] = {
27
27
  subscribe: async function * (_, query, ctx, info) {
@@ -54,7 +54,7 @@ function setupSubscriptions (app, metaMap, resolvers, ignores) {
54
54
  log.warn({ err, entity: field.singularName }, 'graphql subscription error')
55
55
  }
56
56
  }
57
- }
57
+ },
58
58
  }
59
59
 
60
60
  const deleted = `${field.singularName}Deleted`
@@ -63,10 +63,10 @@ function setupSubscriptions (app, metaMap, resolvers, ignores) {
63
63
  name: `${field.name}Deleted`,
64
64
  fields: {
65
65
  [primaryKey]: {
66
- type: meta.fields[primaryKey].type
67
- }
68
- }
69
- })
66
+ type: meta.fields[primaryKey].type,
67
+ },
68
+ },
69
+ }),
70
70
  }
71
71
  resolvers.Subscription[deleted] = {
72
72
  subscribe: async (_, query, ctx, info) => {
@@ -75,12 +75,12 @@ function setupSubscriptions (app, metaMap, resolvers, ignores) {
75
75
  const res = await pubsub.subscribe(topic)
76
76
  ctx.reply.request.log.trace({ topic }, 'subscribed')
77
77
  return wrap(res, deleted)
78
- }
78
+ },
79
79
  }
80
80
  }
81
81
  const subscription = new graphql.GraphQLObjectType({
82
82
  name: 'Subscription',
83
- fields
83
+ fields,
84
84
  })
85
85
 
86
86
  return subscription
package/lib/telemetry.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const telemetryWrapper = (app, fn, operationType, operationName) => async (...args) => {
4
- const { startInternalSpan, endInternalSpan } = app.openTelemetry
4
+ const { startSpan, endSpan } = app.openTelemetry
5
5
  const context = args[2]
6
6
  const request = context?.reply?.request
7
7
  const document = JSON.stringify(request?.body)
@@ -10,19 +10,19 @@ const telemetryWrapper = (app, fn, operationType, operationName) => async (...ar
10
10
  const telemetryAttributes = {
11
11
  'graphql.document': document,
12
12
  'graphql.operation.name': operationName,
13
- 'graphql.operation.type': operationType
13
+ 'graphql.operation.type': operationType,
14
14
  }
15
15
  const spanName = `${operationType} ${operationName}`
16
16
  const ctx = request.span?.context
17
17
 
18
- const span = startInternalSpan(spanName, ctx, telemetryAttributes)
18
+ const span = startSpan(spanName, ctx, telemetryAttributes)
19
19
  try {
20
20
  const result = await fn(...args)
21
- endInternalSpan(span)
21
+ endSpan(span)
22
22
  return result
23
23
  // We ignore this because in sqlite it's HARD to have a resolver exception without a schema validation exception first.
24
24
  } catch (err) /* istanbul ignore next */ {
25
- endInternalSpan(span, err)
25
+ endSpan(span, err)
26
26
  throw err
27
27
  }
28
28
  }
package/lib/utils.js CHANGED
@@ -85,5 +85,5 @@ function fromSelectionSet (selectionSet, fields = new Set()) {
85
85
  module.exports = {
86
86
  sqlTypeToGraphQL,
87
87
  fromSelectionSet,
88
- typeSym: Symbol('graphlType')
88
+ typeSym: Symbol('graphlType'),
89
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-graphql",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.10",
4
4
  "description": "Map SQL dbs to GraphQL",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,41 +17,43 @@
17
17
  "devDependencies": {
18
18
  "@matteo.collina/snap": "^0.3.0",
19
19
  "@matteo.collina/tspl": "^0.1.1",
20
- "@mercuriusjs/gateway": "^3.0.0",
21
- "borp": "^0.16.0",
22
- "fastify": "^4.26.2",
23
- "snazzy": "^9.0.0",
24
- "standard": "^17.1.0",
20
+ "@mercuriusjs/gateway": "^4.0.1",
21
+ "borp": "^0.17.0",
22
+ "eslint": "9",
23
+ "fastify": "^5.0.0-alpha.4",
24
+ "fastify-tsconfig": "^2.0.0",
25
+ "neostandard": "^0.11.1",
25
26
  "tsd": "^0.31.0",
27
+ "typescript": "^5.5.4",
26
28
  "why-is-node-running": "^2.2.2",
27
29
  "ws": "^8.16.0",
28
- "@platformatic/sql-events": "2.0.0-alpha.1",
29
- "@platformatic/sql-mapper": "2.0.0-alpha.1",
30
- "@platformatic/telemetry": "2.0.0-alpha.1"
30
+ "@platformatic/sql-mapper": "2.0.0-alpha.10",
31
+ "@platformatic/telemetry": "2.0.0-alpha.10",
32
+ "@platformatic/sql-events": "2.0.0-alpha.10"
31
33
  },
32
34
  "dependencies": {
33
35
  "@fastify/error": "^3.4.1",
34
- "@mercuriusjs/federation": "^3.0.0",
36
+ "@mercuriusjs/federation": "^4.0.0",
35
37
  "camelcase": "^6.3.0",
36
- "fastify-plugin": "^4.5.1",
38
+ "fastify-plugin": "^5.0.0",
37
39
  "graphql": "^16.8.1",
38
40
  "graphql-scalars": "^1.22.5",
39
41
  "graphql-type-json": "^0.3.2",
40
42
  "inflected": "^2.1.0",
41
- "mercurius": "^14.0.0",
42
- "@platformatic/utils": "2.0.0-alpha.1"
43
+ "mercurius": "^15.0.0",
44
+ "@platformatic/utils": "2.0.0-alpha.10"
43
45
  },
44
46
  "tsd": {
45
47
  "directory": "test/types"
46
48
  },
47
49
  "scripts": {
48
- "lint": "standard | snazzy",
50
+ "lint": "eslint",
49
51
  "test": "npm run lint && npm run test:typescript && npm run test:postgresql && npm run test:mariadb && npm run test:mysql && npm run test:mysql8 && npm run test:sqlite",
50
- "test:postgresql": "DB=postgresql borp --concurrency=1 test/*.test.js",
51
- "test:mariadb": "DB=mariadb borp --concurrency=1 test/*.test.js",
52
- "test:mysql": "DB=mysql borp --concurrency=1 test/*.test.js",
53
- "test:mysql8": "DB=mysql8 borp --concurrency=1 test/*.test.js",
54
- "test:sqlite": "DB=sqlite borp --concurrency=1 test/*.test.js",
52
+ "test:postgresql": "DB=postgresql borp --timeout=180000 --concurrency=1 test/*.test.js",
53
+ "test:mariadb": "DB=mariadb borp --timeout=180000 --concurrency=1 test/*.test.js",
54
+ "test:mysql": "DB=mysql borp --timeout=180000 --concurrency=1 test/*.test.js",
55
+ "test:mysql8": "DB=mysql8 borp --timeout=180000 --concurrency=1 test/*.test.js",
56
+ "test:sqlite": "DB=sqlite borp --timeout=180000 --concurrency=1 test/*.test.js",
55
57
  "test:typescript": "tsd"
56
58
  }
57
59
  }