Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add space between merged SDLs to fix merging errors #899

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/gateway/build-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions test/gateway/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down