From 3408e008bf35305924b52e60a6177f2ebefb4082 Mon Sep 17 00:00:00 2001 From: starptech Date: Sat, 8 May 2021 13:00:24 +0200 Subject: [PATCH] version is required, use join --- src/core/repositories/SchemaRepository.ts | 2 +- .../get-composed-schema-versions.test.ts | 62 ++----------------- .../get-composed-schema-versions.ts | 2 +- 3 files changed, 8 insertions(+), 58 deletions(-) diff --git a/src/core/repositories/SchemaRepository.ts b/src/core/repositories/SchemaRepository.ts index ae15684..6db317e 100644 --- a/src/core/repositories/SchemaRepository.ts +++ b/src/core/repositories/SchemaRepository.ts @@ -60,7 +60,7 @@ export default class SchemaRepository { .andOn(`${ServiceRepository.field('isActive')}`, '=', knex.raw('?', true)) .andOn(`${ServiceRepository.field('name')}`, '=', knex.raw('?', serviceName)) }) - .leftJoin(`${SchemaTagRepository.table}`, function () { + .join(`${SchemaTagRepository.table}`, function () { this.on(`${SchemaRepository.field('id')}`, '=', `${SchemaTagRepository.field('schemaId')}`).andOn( `${SchemaTagRepository.field('isActive')}`, '=', diff --git a/src/registry/federation/get-composed-schema-versions.test.ts b/src/registry/federation/get-composed-schema-versions.test.ts index 94921cd..e13c75f 100644 --- a/src/registry/federation/get-composed-schema-versions.test.ts +++ b/src/registry/federation/get-composed-schema-versions.test.ts @@ -77,49 +77,13 @@ test('Should return schema of two services', async (t) => { }) }) -test('Should return latest schema when no version was specified', async (t) => { +test('Should return valdiation error when no version was specified', async (t) => { const app = build({ databaseConnectionUrl: t.context.connectionUrl, }) t.teardown(() => app.close()) - let res = await app.inject({ - method: 'POST', - url: '/schema/push', - payload: { - typeDefs: `type Query { hello: String }`, - version: '1', - serviceName: `${t.context.testPrefix}_foo`, - graphName: `${t.context.graphName}`, - }, - }) - t.is(res.statusCode, 200) - - res = await app.inject({ - method: 'POST', - url: '/schema/push', - payload: { - typeDefs: `type Query { world: String }`, - version: '2', - serviceName: `${t.context.testPrefix}_bar`, - graphName: `${t.context.graphName}`, - }, - }) - t.is(res.statusCode, 200) - - res = await app.inject({ - method: 'POST', - url: '/schema/push', - payload: { - typeDefs: `type Query { world: String }`, - version: '3', - serviceName: `${t.context.testPrefix}_bar`, - graphName: `${t.context.graphName}`, - }, - }) - t.is(res.statusCode, 200) - - res = await app.inject({ + const res = await app.inject({ method: 'POST', url: '/schema/compose', payload: { @@ -127,32 +91,18 @@ test('Should return latest schema when no version was specified', async (t) => { services: [ { name: `${t.context.testPrefix}_foo`, - }, - { - name: `${t.context.testPrefix}_bar`, - }, + } ], }, }) - t.is(res.statusCode, 200) + t.is(res.statusCode, 400) const response = res.json() - t.true(response.success) - t.is(response.data.length, 2) - - t.like(response.data[0], { - serviceName: `${t.context.testPrefix}_foo`, - typeDefs: 'type Query { hello: String }', - version: '1', - }) + t.false(response.success) - t.like(response.data[1], { - serviceName: `${t.context.testPrefix}_bar`, - typeDefs: 'type Query { world: String }', - version: '3', - }) + t.is(response.error, "body.services[0] should have required property 'version'") }) test('Should return 404 when schema in version could not be found', async (t) => { diff --git a/src/registry/federation/get-composed-schema-versions.ts b/src/registry/federation/get-composed-schema-versions.ts index 517fef9..f71eb80 100644 --- a/src/registry/federation/get-composed-schema-versions.ts +++ b/src/registry/federation/get-composed-schema-versions.ts @@ -48,7 +48,7 @@ export const schema: FastifySchema = { .minItems(1) .items( S.object() - .required(['name']) + .required(['name', 'version']) .prop('version', S.string().minLength(1).maxLength(100)) .prop('name', S.string().minLength(1).pattern('[a-zA-Z_\\-0-9]+')), ),