Skip to content

Commit 7748c0f

Browse files
committed
Add backward compat for old remote servers vs new destination changes
Old fields are now requested by remote clients from old servers, so remote clients can fallback to that data manually if required. New clients + servers can freely use 'destination' instead of the various upstream/hostname fields everywhere.
1 parent 21a1a1f commit 7748c0f

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/admin/mockttp-schema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export const MockttpSchema = gql`
6464
id: String!
6565
6666
destination: Destination!
67+
hostname: String # Deprecated
6768
68-
hostname: String
6969
remoteIpAddress: String!
7070
remotePort: Int!
7171
tags: [String!]!
@@ -76,7 +76,9 @@ export const MockttpSchema = gql`
7676
type TlsHandshakeFailure {
7777
failureCause: String!
7878
79-
hostname: String
79+
destination: Destination
80+
hostname: String # Deprecated
81+
8082
remoteIpAddress: String
8183
remotePort: Int
8284
tags: [String!]!

src/client/mockttp-admin-request-builder.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ export class MockttpAdminRequestBuilder {
230230
${this.schema.asOptionalField('InitiatedRequest', 'remoteIpAddress')}
231231
${this.schema.asOptionalField('InitiatedRequest', 'remotePort')}
232232
233-
${this.schema.asOptionalField('InitiatedRequest', 'destination', 'destination { hostname, port }')}
233+
${this.schema.typeHasField('InitiatedRequest', 'destination')
234+
? 'destination { hostname, port }'
235+
: 'hostname' // Backward compat for old servers
236+
}
234237
235238
rawHeaders
236239
timingEvents
@@ -249,7 +252,10 @@ export class MockttpAdminRequestBuilder {
249252
${this.schema.asOptionalField('Request', 'remoteIpAddress')}
250253
${this.schema.asOptionalField('Request', 'remotePort')}
251254
252-
${this.schema.asOptionalField('Request', 'destination', 'destination { hostname, port }')}
255+
${this.schema.typeHasField('Request', 'destination')
256+
? 'destination { hostname, port }'
257+
: 'hostname' // Backward compat for old servers
258+
}
253259
254260
rawHeaders
255261
body
@@ -285,7 +291,10 @@ export class MockttpAdminRequestBuilder {
285291
remoteIpAddress
286292
remotePort
287293
288-
${this.schema.asOptionalField('Request', 'destination', 'destination { hostname, port }')}
294+
${this.schema.typeHasField('Request', 'destination')
295+
? 'destination { hostname, port }'
296+
: 'hostname' // Backward compat for old servers
297+
}
289298
290299
rawHeaders
291300
body
@@ -353,7 +362,10 @@ export class MockttpAdminRequestBuilder {
353362
url
354363
path
355364
356-
${this.schema.asOptionalField('AbortedRequest', 'destination', 'destination { hostname, port }')}
365+
${this.schema.typeHasField('AbortedRequest', 'destination')
366+
? 'destination { hostname, port }'
367+
: 'hostname' // Backward compat for old servers
368+
}
357369
358370
rawHeaders
359371
@@ -406,7 +418,12 @@ export class MockttpAdminRequestBuilder {
406418
'tls-client-error': gql`subscription OnTlsClientError {
407419
failedTlsRequest {
408420
failureCause
409-
hostname
421+
422+
${this.schema.typeHasField('TlsHandshakeFailure', 'destination')
423+
? 'destination { hostname, port }'
424+
: 'hostname'
425+
}
426+
410427
remoteIpAddress
411428
remotePort
412429
tags

0 commit comments

Comments
 (0)