@platformatic/service 0.26.0 → 0.26.1
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/index.js +0 -11
- package/package.json +6 -6
- package/test/fixtures/throw-resolver.js +16 -0
- package/test/graphql.test.js +61 -0
package/index.js
CHANGED
|
@@ -26,17 +26,6 @@ async function platformaticService (app, opts, toLoad = []) {
|
|
|
26
26
|
app.register(setupMetrics, config.metrics)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
app.setErrorHandler(async (err, req, reply) => {
|
|
30
|
-
if (!(err instanceof Error)) {
|
|
31
|
-
req.log.debug({ err }, 'error encountered within the sandbox, wrapping it')
|
|
32
|
-
const newError = new Error(err.message)
|
|
33
|
-
newError.cause = err
|
|
34
|
-
newError.statusCode = err.statusCode || 500
|
|
35
|
-
err = newError
|
|
36
|
-
}
|
|
37
|
-
throw err
|
|
38
|
-
})
|
|
39
|
-
|
|
40
29
|
if (Array.isArray(toLoad)) {
|
|
41
30
|
for (const plugin of toLoad) {
|
|
42
31
|
await app.register(plugin)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"fastify": "^4.17.0",
|
|
56
56
|
"fastify-metrics": "^10.3.0",
|
|
57
57
|
"fastify-plugin": "^4.5.0",
|
|
58
|
-
"fastify-sandbox": "^0.13.
|
|
58
|
+
"fastify-sandbox": "^0.13.1",
|
|
59
59
|
"graphql": "^16.6.0",
|
|
60
60
|
"help-me": "^4.2.0",
|
|
61
61
|
"mercurius": "^13.0.0",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"pino-pretty": "^10.0.0",
|
|
65
65
|
"rfdc": "^1.3.0",
|
|
66
66
|
"ua-parser-js": "^1.0.35",
|
|
67
|
-
"@platformatic/
|
|
68
|
-
"@platformatic/
|
|
69
|
-
"@platformatic/
|
|
70
|
-
"@platformatic/
|
|
67
|
+
"@platformatic/client": "0.26.1",
|
|
68
|
+
"@platformatic/swagger-ui-theme": "0.26.1",
|
|
69
|
+
"@platformatic/config": "0.26.1",
|
|
70
|
+
"@platformatic/utils": "0.26.1"
|
|
71
71
|
},
|
|
72
72
|
"standard": {
|
|
73
73
|
"ignore": [
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = async function (app) {
|
|
4
|
+
app.graphql.extendSchema(`
|
|
5
|
+
extend type Query {
|
|
6
|
+
hello: String
|
|
7
|
+
}
|
|
8
|
+
`)
|
|
9
|
+
app.graphql.defineResolvers({
|
|
10
|
+
Query: {
|
|
11
|
+
hello: async function (root, args, context) {
|
|
12
|
+
throw new Error('Kaboooooom!!!')
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
}
|
package/test/graphql.test.js
CHANGED
|
@@ -156,3 +156,64 @@ test('graphql disabled by default', async ({ teardown, equal, fail }) => {
|
|
|
156
156
|
equal(err.message, 'Cannot read properties of undefined (reading \'extendSchema\')')
|
|
157
157
|
}
|
|
158
158
|
})
|
|
159
|
+
|
|
160
|
+
test('graphql errors are correctly propagated in custom resolvers', async ({ teardown, equal, same }) => {
|
|
161
|
+
const app = await buildServer(buildConfig({
|
|
162
|
+
server: {
|
|
163
|
+
hostname: '127.0.0.1',
|
|
164
|
+
port: 0,
|
|
165
|
+
healthCheck: {
|
|
166
|
+
enabled: true,
|
|
167
|
+
interval: 2000
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
service: {
|
|
171
|
+
graphql: true
|
|
172
|
+
},
|
|
173
|
+
plugins: {
|
|
174
|
+
paths: [join(__dirname, 'fixtures', 'throw-resolver.js')]
|
|
175
|
+
}
|
|
176
|
+
}))
|
|
177
|
+
|
|
178
|
+
teardown(async () => {
|
|
179
|
+
await app.close()
|
|
180
|
+
})
|
|
181
|
+
await app.start()
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
const res = await request(`${app.url}/graphql`, {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: {
|
|
187
|
+
'content-type': 'application/json'
|
|
188
|
+
},
|
|
189
|
+
body: JSON.stringify({
|
|
190
|
+
query: `
|
|
191
|
+
query {
|
|
192
|
+
hello
|
|
193
|
+
}
|
|
194
|
+
`
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
equal(res.statusCode, 200, 'hello status code')
|
|
198
|
+
same(await res.body.json(), {
|
|
199
|
+
data: {
|
|
200
|
+
hello: null
|
|
201
|
+
},
|
|
202
|
+
errors: [
|
|
203
|
+
{
|
|
204
|
+
message: 'Kaboooooom!!!',
|
|
205
|
+
locations: [{
|
|
206
|
+
line: 3,
|
|
207
|
+
column: 13
|
|
208
|
+
}],
|
|
209
|
+
path: ['hello']
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
}, 'hello response')
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
{
|
|
216
|
+
const res = await request(`${app.url}/graphiql`)
|
|
217
|
+
equal(res.statusCode, 200, 'graphiql status code')
|
|
218
|
+
}
|
|
219
|
+
})
|