Skip to content

Commit

Permalink
version is required, use join
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed May 8, 2021
1 parent 9503389 commit 3408e00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/core/repositories/SchemaRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`,
'=',
Expand Down
62 changes: 6 additions & 56 deletions src/registry/federation/get-composed-schema-versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,82 +77,32 @@ 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: {
graphName: `${t.context.graphName}`,
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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/federation/get-composed-schema-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+')),
),
Expand Down

0 comments on commit 3408e00

Please sign in to comment.