Skip to content

Commit 27457d9

Browse files
committed
implement routingUrl, dont expose internal errors
1 parent 0db468f commit 27457d9

25 files changed

+402
-43
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
DATABASE_URL="postgresql://postgres:changeme@localhost:5440/graphql-registry?schema=public"
22
BASIC_AUTH=123,456
3-
JWT_SECRET=secret
3+
JWT_SECRET=secret
4+
PRETTY_PRINT=true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Try all endpoints in [insomnia](https://insomnia.rest/run/?label=GraphQL%20Regis
3939
## Big Picture
4040

4141
<div align="center">
42-
<img src="./docs/usecases.png" alt="graphql-registry" width="800" />
42+
<img src="./docs/usecases-01.png" alt="graphql-registry" width="800" />
4343
</div>
4444

4545
## Development

benchmark/composed-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export let options = {
55
vus: 2,
66
duration: '10s',
77
thresholds: {
8-
http_req_duration: ['p(99)<800'], // 99% of requests must complete below 0.8s
8+
http_req_duration: ['p(99)<500'], // 99% of requests must complete below 0.5s
99
},
1010
}
1111
const BASE_URL = `${__ENV.URL}`

docs/api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GET - `/schema/latest?graphName=my_graph` Returns the last registered (time-base
3131

3232
### Register a schema
3333

34-
POST - `/schema/push` Creates a new graph and schema for a service. If you omit the `version` field the schema is registered as `current` version. `current` always represent the last registered schema that was pushed without a version.
34+
POST - `/schema/push` Creates a new graph and schema for a service. If you omit the `version` field the schema is registered as `current` version. `current` always represent the last registered schema that was pushed without a version. Optionally, you can pass `routingUrl` field. The URL that your gateway uses to communicate with the service in a [managed federation](https://www.apollographql.com/docs/federation/managed-federation/overview/) architecture.
3535

3636
**Notice:** A schema is normalized before it's stored in the database. Whitespaces are stipped and graphql elements are sorted lexicographically.
3737

@@ -44,7 +44,8 @@ POST - `/schema/push` Creates a new graph and schema for a service. If you omit
4444
"typeDefs": "type Query { hello: String }",
4545
"graphName": "my_graph",
4646
"serviceName": "foo",
47-
"version": "1" // optional, uses "current" by default
47+
"version": "1", // optional, uses "current" by default
48+
"routingUrl": "http://products-graphql.svc.cluster.local:4001/graphql" // optional, for managed federation
4849
}
4950
```
5051

docs/usecases-01.png

211 KB
Loading

docs/usecases.png

-146 KB
Binary file not shown.

package-lock.json

Lines changed: 122 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
"uid": "^2.0.0"
6565
},
6666
"dependencies": {
67-
"ajv": "6.12.6",
6867
"@apollo/federation": "^0.25.0",
6968
"@graphql-inspector/core": "2.5.0",
69+
"ajv": "6.12.6",
7070
"env-schema": "^3.0.1",
7171
"fastify": "^3.15.1",
7272
"fastify-basic-auth": "^2.0.0",
@@ -76,7 +76,8 @@
7676
"fluent-json-schema": "^3.0.0",
7777
"graphql": "^15.5.0",
7878
"knex": "^0.95.5",
79-
"pg": "^8.6.0"
79+
"pg": "^8.6.0",
80+
"pino-pretty": "^4.8.0"
8081
},
8182
"keywords": [
8283
"graphql",

src/build-server.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ import registryPlugin from './registry'
33
import health from './core/health'
44
import knexPlugin from './core/knex-plugin'
55
import validatorPlugin from './core/validator-plugin'
6+
import { ErrorResponse } from './core/types'
67

78
export interface buildOptions {
89
logger?: boolean
910
databaseConnectionUrl: string
1011
basicAuth?: string
12+
prettyPrint?: boolean
1113
jwtSecret?: string
1214
}
1315

1416
export default function build(opts: buildOptions) {
1517
const fastify = Fastify({
16-
logger: opts.logger,
18+
logger: opts.logger
19+
? {
20+
prettyPrint: opts.prettyPrint,
21+
}
22+
: undefined,
1723
})
1824

1925
// Custom ajv validator
@@ -43,11 +49,15 @@ export default function build(opts: buildOptions) {
4349
})
4450
return
4551
}
46-
reply.code(err.statusCode || 500)
47-
reply.send({
52+
const result: ErrorResponse = {
4853
success: false,
49-
error: err.message,
50-
})
54+
}
55+
// only expose error informations when it was intented for
56+
if (err.name === 'FastifyError') {
57+
result.error = err.message
58+
}
59+
60+
reply.code(err.statusCode || 500).send(result)
5161
})
5262

5363
return fastify

src/core/env.schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export default S.object()
44
.prop('DATABASE_URL', S.string())
55
.prop('BASIC_AUTH', S.string())
66
.prop('JWT_SECRET', S.string())
7+
.prop('PRETTY_PRINT', S.boolean().default(false))
78
.prop('LOGGER', S.boolean().default(true)) as any
89

910
export interface AppSchema {
1011
DATABASE_URL: string
12+
PRETTY_PRINT: boolean
1113
LOGGER: boolean
1214
BASIC_AUTH: string
1315
JWT_SECRET: string

0 commit comments

Comments
 (0)