Skip to content

Commit 0e1d215

Browse files
committed
Return metadata from the activate/deactivate API
Previously this just returned a boolean. This is technically a breaking change, as it now returns a JSON object, with the result in the .success field, but nobody should be depending on this internal API except the UI, and that doesn't depend on the result for anything substantial. Using JSON here instead of a proper result is a compatibility workaround. In future, the plan is to remove GraphQL entirely, which is why I'm not extending the complexity of the schema at this stage.
1 parent 86e2f81 commit 0e1d215

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/hide-chrome-warning-server.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { getLocal, Mockttp } from 'mockttp';
22

3-
// Make the types for some of the browser code below happy.
4-
let targetUrl: string;
5-
63
// The first tab that opens opens with a Chrome warning about dangerous flags
74
// Closing it and immediately opening a new one is a bit cheeky, but
85
// is completely gets rid that, more or less invisibly:

src/httptoolkit-server.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const typeDefs = `
2525
id: ID!,
2626
proxyPort: Int!,
2727
options: Json
28-
): Boolean!
28+
): Json
2929
deactivateInterceptor(
3030
id: ID!,
3131
proxyPort: Int!
@@ -74,8 +74,11 @@ const buildResolvers = (
7474
const interceptor = interceptors[id];
7575
if (!interceptor) throw new Error(`Unknown interceptor ${id}`);
7676

77+
let metadata: any = null;
7778
await Promise.race([
78-
interceptor.activate(proxyPort, options).catch(reportError),
79+
interceptor.activate(proxyPort, options)
80+
.then((result) => metadata = result)
81+
.catch(reportError),
7982
delay(30000) // After 30s, we don't stop activating, but we do report failure
8083
]);
8184

@@ -87,7 +90,7 @@ const buildResolvers = (
8790
reportError(new Error(`Failed to activate ${id}`));
8891
}
8992

90-
return isActive;
93+
return { success: isActive, metadata };
9194
},
9295
deactivateInterceptor: async (__: void, args: _.Dictionary<any>) => {
9396
const { id, proxyPort, options } = args;
@@ -96,7 +99,7 @@ const buildResolvers = (
9699
if (!interceptor) throw new Error(`Unknown interceptor ${id}`);
97100

98101
await interceptor.deactivate(proxyPort, options).catch(reportError);
99-
return !interceptor.isActive(proxyPort);
102+
return { success: !interceptor.isActive(proxyPort) };
100103
},
101104
triggerUpdate: () => {
102105
eventEmitter.emit('update-requested');

src/interceptors/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface Interceptor {
1414
isActivable(): Promise<boolean>;
1515
isActive(proxyPort: number): boolean;
1616

17-
activate(proxyPort: number, options?: any): Promise<void>;
18-
deactivate(proxyPort: number, options?: any): Promise<void>;
17+
activate(proxyPort: number, options?: any): Promise<void | {}>;
18+
deactivate(proxyPort: number, options?: any): Promise<void | {}>;
1919
deactivateAll(): Promise<void>;
2020
}
2121

0 commit comments

Comments
 (0)