Skip to content

Commit

Permalink
fix(deps): update whatwg-node (#7553)
Browse files Browse the repository at this point in the history
* fix(deps): update whatwg-node

* chore(dependencies): updated changesets for modified dependencies

* Fix cleanup logic

* Fix e2e

* Use waitUntil

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Arda TANRIKULU <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent e39a34d commit e49a7e6
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 109 deletions.
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_cache-redis-7553-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/cache-redis": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/disposablestack@^0.0.2` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.2) (from `^0.0.1`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_fusion-runtime-7553-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/fusion-runtime": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/disposablestack@^0.0.2` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.2) (from `^0.0.1`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_serve-runtime-7553-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/serve-runtime": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/disposablestack@^0.0.2` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.2) (from `^0.0.1`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_utils-7553-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/utils": patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/disposablestack@^0.0.2` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.2) (from `^0.0.1`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/small-badgers-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/fusion-runtime': patch
---

Fix transport cleanup logic
42 changes: 22 additions & 20 deletions e2e/json-schema-subscriptions/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const opts = Opts(process.argv);

let todos = [];

const app = createRouter()
const app = createRouter<FetchEvent>()
.route({
path: '/todos',
method: 'GET',
Expand All @@ -16,31 +16,33 @@ const app = createRouter()
.route({
path: '/todo',
method: 'POST',
async handler(request) {
async handler(request, { waitUntil }) {
const reqBody = await request.json();
const todo = {
id: todos.length,
...reqBody,
};
todos.push(todo);
await fetch(`http://0.0.0.0:${opts.getPort(true)}/webhooks/todo_added`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(todo),
})
.then(res =>
res.text().then(resText =>
console.log('Webhook payload sent', {
status: res.status,
statusText: res.statusText,
body: resText,
headers: Object.fromEntries(res.headers.entries()),
}),
),
)
.catch(err => console.error('Webhook payload failed', err));
waitUntil(
fetch(`http://0.0.0.0:${opts.getPort(true)}/webhooks/todo_added`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(todo),
})
.then(res =>
res.text().then(resText =>
console.log('Webhook payload sent', {
status: res.status,
statusText: res.statusText,
body: resText,
headers: Object.fromEntries(res.headers.entries()),
}),
),
)
.catch(err => console.error('Webhook payload failed', err)),
);
return Response.json(todo);
},
});
Expand Down
45 changes: 25 additions & 20 deletions e2e/openapi-subscriptions/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ import urljoin from 'url-join';
import { Opts } from '@e2e/opts';
import { fetch } from '@whatwg-node/fetch';

const app = createRouter().route({
const app = createRouter<FetchEvent>().route({
method: 'POST',
path: '/streams',
handler(req) {
handler(req, { waitUntil }) {
const subscriptionId = Date.now().toString();
req.json().then(async ({ callbackUrl }) => {
for (let i = 0; i < 10; i++) {
const body = JSON.stringify({
timestamp: new Date().toJSON(),
userData: 'RANDOM_DATA',
});
const fullCallbackUrl = urljoin(callbackUrl, subscriptionId);
console.info(`Webhook ping ${i + 1} out of 10 -> `, fullCallbackUrl, body);
const res = await fetch(fullCallbackUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
});
console.info(`Webhook response ${i + 1} -> `, res.status, res.statusText);
}
});
waitUntil(
req.json().then(async ({ callbackUrl }) => {
for (let i = 0; i < 10; i++) {
const body = JSON.stringify({
timestamp: new Date().toJSON(),
userData: 'RANDOM_DATA',
});
const fullCallbackUrl = urljoin(callbackUrl, subscriptionId);
console.info(`Webhook ping ${i + 1} out of 10 -> `, fullCallbackUrl, body);
await fetch(fullCallbackUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
})
.then(res => {
console.info(`Webhook response ${i + 1} -> `, res.status, res.statusText);
})
.catch(err => console.error(`Webhook error ${i + 1} -> `, err));
}
}),
);
return Response.json({ subscriptionId });
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@graphql-mesh/string-interpolation": "0.5.6",
"@whatwg-node/disposablestack": "^0.0.1",
"@whatwg-node/disposablestack": "^0.0.2",
"ioredis": "^5.3.2",
"ioredis-mock": "^8.8.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fusion/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@graphql-tools/stitching-directives": "^3.1.2",
"@graphql-tools/utils": "^10.5.3",
"@graphql-tools/wrap": "^10.0.5",
"@whatwg-node/disposablestack": "^0.0.1",
"@whatwg-node/disposablestack": "^0.0.2",
"change-case": "^4.1.2",
"graphql-yoga": "^5.7.0",
"tslib": "^2.4.0"
Expand Down
98 changes: 50 additions & 48 deletions packages/fusion/runtime/src/unifiedGraphManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,57 +147,59 @@ export class UnifiedGraphManager<TContext> {
if (this.lastLoadedUnifiedGraph != null) {
this.opts.transportContext?.logger?.debug('Unified Graph changed, updating...');
}
let cleanupJob$: Promise<true>;
let cleanupJob$: MaybePromise<void>;
if (this._transportExecutorStack) {
cleanupJob$ = this._transportExecutorStack.disposeAsync().then(() => true);
cleanupJob$ = this._transportExecutorStack.disposeAsync();
}
this._transportExecutorStack = new AsyncDisposableStack();
this.lastLoadedUnifiedGraph ||= loadedUnifiedGraph;
this.lastLoadedUnifiedGraph = loadedUnifiedGraph;
this.unifiedGraph = ensureSchema(loadedUnifiedGraph);
const {
unifiedGraph: newUnifiedGraph,
transportEntryMap,
subschemas,
additionalResolvers,
} = this.handleUnifiedGraph({
unifiedGraph: this.unifiedGraph,
additionalTypeDefs: this.opts.additionalTypeDefs,
additionalResolvers: this.opts.additionalResolvers,
onSubgraphExecute(subgraphName, execReq) {
return onSubgraphExecute(subgraphName, execReq);
},
transportEntryAdditions: this.opts.transportEntryAdditions,
batch: this.batch,
});
this.unifiedGraph = newUnifiedGraph;
const onSubgraphExecute = getOnSubgraphExecute({
onSubgraphExecuteHooks: this.onSubgraphExecuteHooks,
transports: this.opts.transports,
transportContext: this.opts.transportContext,
transportEntryMap,
getSubgraphSchema(subgraphName) {
const subgraph = subschemas.find(s => compareSubgraphNames(s.name, subgraphName));
if (!subgraph) {
throw new Error(`Subgraph ${subgraphName} not found`);
}
return subgraph.schema;
},
transportExecutorStack: this._transportExecutorStack,
});
if (this.opts.additionalResolvers || additionalResolvers.length) {
this.inContextSDK = getInContextSDK(
this.unifiedGraph,
// @ts-expect-error Legacy Mesh RawSource is not compatible with new Mesh
return mapMaybePromise(cleanupJob$, () => {
this._transportExecutorStack = new AsyncDisposableStack();
this.lastLoadedUnifiedGraph ||= loadedUnifiedGraph;
this.lastLoadedUnifiedGraph = loadedUnifiedGraph;
this.unifiedGraph = ensureSchema(loadedUnifiedGraph);
const {
unifiedGraph: newUnifiedGraph,
transportEntryMap,
subschemas,
this.opts.transportContext?.logger,
this.opts.onDelegateHooks || [],
);
}
this.continuePolling();
this._transportEntryMap = transportEntryMap;
this.opts.onSchemaChange?.(this.unifiedGraph);
return cleanupJob$ || true;
additionalResolvers,
} = this.handleUnifiedGraph({
unifiedGraph: this.unifiedGraph,
additionalTypeDefs: this.opts.additionalTypeDefs,
additionalResolvers: this.opts.additionalResolvers,
onSubgraphExecute(subgraphName, execReq) {
return onSubgraphExecute(subgraphName, execReq);
},
transportEntryAdditions: this.opts.transportEntryAdditions,
batch: this.batch,
});
this.unifiedGraph = newUnifiedGraph;
const onSubgraphExecute = getOnSubgraphExecute({
onSubgraphExecuteHooks: this.onSubgraphExecuteHooks,
transports: this.opts.transports,
transportContext: this.opts.transportContext,
transportEntryMap,
getSubgraphSchema(subgraphName) {
const subgraph = subschemas.find(s => compareSubgraphNames(s.name, subgraphName));
if (!subgraph) {
throw new Error(`Subgraph ${subgraphName} not found`);
}
return subgraph.schema;
},
transportExecutorStack: this._transportExecutorStack,
});
if (this.opts.additionalResolvers || additionalResolvers.length) {
this.inContextSDK = getInContextSDK(
this.unifiedGraph,
// @ts-expect-error Legacy Mesh RawSource is not compatible with new Mesh
subschemas,
this.opts.transportContext?.logger,
this.opts.onDelegateHooks || [],
);
}
this.continuePolling();
this._transportEntryMap = transportEntryMap;
this.opts.onSchemaChange?.(this.unifiedGraph);
return true;
});
},
err => {
this.opts.transportContext?.logger?.error('Failed to load Supergraph', err);
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@graphql-mesh/string-interpolation": "^0.5.6",
"@graphql-tools/delegate": "^10.0.19",
"@whatwg-node/disposablestack": "^0.0.1",
"@whatwg-node/disposablestack": "^0.0.2",
"@whatwg-node/fetch": "^0.9.13",
"dset": "^3.1.2",
"js-yaml": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@graphql-tools/utils": "10.5.4",
"@whatwg-node/fetch": "0.9.20",
"@whatwg-node/fetch": "0.9.21",
"fets": "0.8.3",
"graphql-yoga": "5.7.0",
"json-bigint-patch": "0.0.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/deduplicate-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@whatwg-node/fetch": "0.9.20"
"@whatwg-node/fetch": "0.9.21"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/serve-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@graphql-tools/utils": "^10.5.3",
"@graphql-tools/wrap": "^10.0.5",
"@graphql-yoga/plugin-apollo-usage-report": "^0.1.0",
"@whatwg-node/disposablestack": "^0.0.1",
"@whatwg-node/disposablestack": "^0.0.2",
"@whatwg-node/server": "^0.9.46",
"graphql-yoga": "^5.7.0"
},
Expand Down
Loading

0 comments on commit e49a7e6

Please sign in to comment.