mercurius
Advanced tools
Comparing version 9.4.0 to 9.5.0
19
index.js
@@ -154,2 +154,21 @@ 'use strict' | ||
if (gateway && Array.isArray(gateway.services)) { | ||
const serviceNames = new Set() | ||
for (const service of gateway.services) { | ||
if (typeof service !== 'object') { | ||
throw new MER_ERR_INVALID_OPTS('gateway: all "services" must be objects') | ||
} | ||
if (typeof service.name !== 'string') { | ||
throw new MER_ERR_INVALID_OPTS('gateway: all "services" must have a "name" String property') | ||
} | ||
if (serviceNames.has(service.name)) { | ||
throw new MER_ERR_INVALID_OPTS(`gateway: all "services" must have a unique "name": "${service.name}" is already used`) | ||
} | ||
serviceNames.add(service.name) | ||
if (typeof service.url !== 'string' && (!Array.isArray(service.url) || service.url.length === 0 || !service.url.every(url => typeof url === 'string'))) { | ||
throw new MER_ERR_INVALID_OPTS('gateway: all "services" must have an "url" String, or a non-empty Array of String, property') | ||
} | ||
} | ||
} | ||
if (Array.isArray(schema)) { | ||
@@ -156,0 +175,0 @@ schema = schema.join('\n') |
{ | ||
"name": "mercurius", | ||
"version": "9.4.0", | ||
"version": "9.5.0", | ||
"description": "Fastify GraphQL adapter with gateway and subscription support", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -62,1 +62,146 @@ 'use strict' | ||
}) | ||
test('Each "gateway" option "services" must be an object', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
'foo' | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must be objects') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have a "name"', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{} | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have a "name" String property') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have a "name" that is a String', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 42 } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have a "name" String property') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have a "name" that is unique', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 'foo', url: 'https://foo' }, | ||
{ name: 'foo' } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have a unique "name": "foo" is already used') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have an "url"', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 'foo' } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have an "url" String, or a non-empty Array of String, property') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have an "url" that is a String or an Array', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 'foo', url: new URL('https://foo') } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have an "url" String, or a non-empty Array of String, property') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have an "url" that, if it is an Array, should not be empty', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 'foo', url: [] } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have an "url" String, or a non-empty Array of String, property') | ||
} | ||
}) | ||
test('Each "gateway" option "services" must have an "url" that, if it is a non-empty Array, should be filled with Strings only', async (t) => { | ||
const app = Fastify() | ||
app.register(GQL, { | ||
gateway: { | ||
services: [ | ||
{ name: 'foo', url: [new URL('https://foo')] } | ||
] | ||
} | ||
}) | ||
try { | ||
await app.ready() | ||
} catch (err) { | ||
t.equal(err.message, 'Invalid options: gateway: all "services" must have an "url" String, or a non-empty Array of String, property') | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
979164
34571