diff --git a/lib/gateway/build-gateway.js b/lib/gateway/build-gateway.js index bdac04c7..758792f3 100644 --- a/lib/gateway/build-gateway.js +++ b/lib/gateway/build-gateway.js @@ -313,7 +313,7 @@ async function buildGateway (gatewayOpts, app) { throw new MER_ERR_GQL_GATEWAY_INIT('No valid service SDLs were provided') } - const schema = buildFederatedSchema(serviceSDLs.join(''), true) + const schema = buildFederatedSchema(serviceSDLs.join(' '), true) const typeToServiceMap = {} const typeFieldsToService = {} @@ -419,7 +419,7 @@ async function buildGateway (gatewayOpts, app) { async refresh (isRetry) { const failedMandatoryServices = [] if (this._serviceSDLs === undefined) { - this._serviceSDLs = serviceSDLs.join('') + this._serviceSDLs = serviceSDLs.join(' ') } const $refreshResult = await Promise.allSettled( @@ -458,7 +458,7 @@ async function buildGateway (gatewayOpts, app) { const _serviceSDLs = Object.values(serviceMap) .map((service) => service.schemaDefinition) - .join('') + .join(' ') if (this._serviceSDLs === _serviceSDLs) { return null diff --git a/test/gateway/schema.js b/test/gateway/schema.js index 13bdecd7..e2fce8fe 100644 --- a/test/gateway/schema.js +++ b/test/gateway/schema.js @@ -302,6 +302,65 @@ test('It builds the gateway schema correctly', async (t) => { }) }) +test('Should merge schemas correctly', async (t) => { + const [helloService, helloServicePort] = await createService( + t, + 'extend type Query { hello: String } directive @customDirective on FIELD_DEFINITION', + { Query: { hello: () => 'World' } } + ) + + const [worldService, worldServicePort] = await createService( + t, + 'extend type Query { world: String }', + { Query: { world: () => 'Hello' } } + ) + + const gateway = Fastify() + + t.teardown(async () => { + await gateway.close() + await helloService.close() + await worldService.close() + }) + + gateway.register(GQL, { + gateway: { + services: [{ + name: 'hello', + url: `http://localhost:${helloServicePort}/graphql` + }, { + name: 'world', + url: `http://localhost:${worldServicePort}/graphql` + }] + } + }) + + const query = ` + query { + hello + world + } + ` + + const res = await gateway.inject({ + method: 'POST', + headers: { + 'content-type': 'application/json' + }, + url: '/graphql', + body: JSON.stringify({ + query + }) + }) + + t.same(JSON.parse(res.body), { + data: { + hello: 'World', + world: 'Hello' + } + }) +}) + test('It support variable inside nested arguments', async (t) => { const user = { id: 'u1',