@platformatic/runtime 1.5.1 → 1.5.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.
@@ -5,7 +5,10 @@
5
5
  "hotReload": false,
6
6
  "autoload": {
7
7
  "path": "../monorepo",
8
- "exclude": ["docs", "composerApp"],
8
+ "exclude": [
9
+ "docs",
10
+ "composerApp"
11
+ ],
9
12
  "mappings": {
10
13
  "serviceAppWithLogger": {
11
14
  "id": "with-logger",
@@ -14,6 +17,10 @@
14
17
  "serviceAppWithMultiplePlugins": {
15
18
  "id": "multi-plugin-service",
16
19
  "config": "platformatic.service.json"
20
+ },
21
+ "dbApp": {
22
+ "id": "db-app",
23
+ "config": "platformatic.db.json"
17
24
  }
18
25
  }
19
26
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.22.0/db",
3
+ "server": {
4
+ "hostname": "127.0.0.1",
5
+ "port": 0
6
+ },
7
+ "db": {
8
+ "connectionString": "sqlite://db.sqlite",
9
+ "graphql": true,
10
+ "openapi": false,
11
+ "ignore": {
12
+ "versions": true
13
+ },
14
+ "events": false
15
+ }
16
+ }
package/lib/api-client.js CHANGED
@@ -52,6 +52,10 @@ class RuntimeApiClient extends EventEmitter {
52
52
  return this.#sendCommand('plt:get-service-openapi-schema', { id })
53
53
  }
54
54
 
55
+ async getServiceGraphqlSchema (id) {
56
+ return this.#sendCommand('plt:get-service-graphql-schema', { id })
57
+ }
58
+
55
59
  async startService (id) {
56
60
  return this.#sendCommand('plt:start-service', { id })
57
61
  }
package/lib/api.js CHANGED
@@ -4,6 +4,7 @@ const FastifyUndiciDispatcher = require('fastify-undici-dispatcher')
4
4
  const { Agent, setGlobalDispatcher } = require('undici')
5
5
  const { PlatformaticApp } = require('./app')
6
6
  const errors = require('./errors')
7
+ const { printSchema } = require('graphql')
7
8
 
8
9
  class RuntimeApi {
9
10
  #services
@@ -101,6 +102,8 @@ class RuntimeApi {
101
102
  return this.#getServiceConfig(params)
102
103
  case 'plt:get-service-openapi-schema':
103
104
  return this.#getServiceOpenapiSchema(params)
105
+ case 'plt:get-service-graphql-schema':
106
+ return this.#getServiceGraphqlSchema(params)
104
107
  case 'plt:start-service':
105
108
  return this.#startService(params)
106
109
  case 'plt:stop-service':
@@ -218,6 +221,26 @@ class RuntimeApi {
218
221
  }
219
222
  }
220
223
 
224
+ async #getServiceGraphqlSchema ({ id }) {
225
+ const service = this.#getServiceById(id)
226
+
227
+ if (!service.config) {
228
+ throw new errors.ServiceNotStartedError(id)
229
+ }
230
+
231
+ if (typeof service.server.graphql !== 'function') {
232
+ return null
233
+ }
234
+
235
+ try {
236
+ await service.server.ready()
237
+ const graphqlSchema = printSchema(service.server.graphql.schema)
238
+ return graphqlSchema
239
+ } catch (err) {
240
+ throw new errors.FailedToRetrieveGraphQLSchemaError(id, err.message)
241
+ }
242
+ }
243
+
221
244
  async #startService ({ id }) {
222
245
  const service = this.#getServiceById(id)
223
246
  await service.start()
package/lib/errors.js CHANGED
@@ -10,6 +10,7 @@ module.exports = {
10
10
  ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, "Service with id '%s' not found"),
11
11
  ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
12
12
  FailedToRetrieveOpenAPISchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`, 'Failed to retrieve OpenAPI schema for service with id "%s": %s'),
13
+ FailedToRetrieveGraphQLSchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`, 'Failed to retrieve GraphQL schema for service with id "%s": %s'),
13
14
  ApplicationAlreadyStartedError: createError(`${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`, 'Application is already started'),
14
15
  ApplicationNotStartedError: createError(`${ERROR_PREFIX}_APPLICATION_NOT_STARTED`, 'Application has not been started'),
15
16
  ConfigPathMustBeStringError: createError(`${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`, 'Config path must be a string'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -27,8 +27,8 @@
27
27
  "standard": "^17.1.0",
28
28
  "tsd": "^0.29.0",
29
29
  "typescript": "^5.2.2",
30
- "@platformatic/sql-graphql": "1.5.1",
31
- "@platformatic/sql-mapper": "1.5.1"
30
+ "@platformatic/sql-graphql": "1.5.2",
31
+ "@platformatic/sql-mapper": "1.5.2"
32
32
  },
33
33
  "dependencies": {
34
34
  "@fastify/error": "^3.4.0",
@@ -41,17 +41,18 @@
41
41
  "fastest-levenshtein": "^1.0.16",
42
42
  "fastify": "^4.24.1",
43
43
  "fastify-undici-dispatcher": "^0.5.0",
44
+ "graphql": "^16.8.1",
44
45
  "help-me": "^4.2.0",
45
46
  "minimist": "^1.2.8",
46
47
  "pino": "^8.16.0",
47
48
  "pino-pretty": "^10.2.3",
48
49
  "undici": "^5.26.3",
49
- "@platformatic/composer": "1.5.1",
50
- "@platformatic/config": "1.5.1",
51
- "@platformatic/db": "1.5.1",
52
- "@platformatic/service": "1.5.1",
53
- "@platformatic/telemetry": "1.5.1",
54
- "@platformatic/utils": "1.5.1"
50
+ "@platformatic/composer": "1.5.2",
51
+ "@platformatic/config": "1.5.2",
52
+ "@platformatic/db": "1.5.2",
53
+ "@platformatic/service": "1.5.2",
54
+ "@platformatic/telemetry": "1.5.2",
55
+ "@platformatic/utils": "1.5.2"
55
56
  },
56
57
  "standard": {
57
58
  "ignore": [