Skip to content

Commit 34294ea

Browse files
fix(@graphql-mesh/transport-http): infinite loop on subscriptions without kind (#1385)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a832e7b commit 34294ea

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

.changeset/fast-parrots-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-mesh/transport-http': patch
3+
---
4+
5+
Fix an infinite loop when providing options for subscriptions transport of subgraphs using HTTP transport for both queries/mutations and subscrpitions.

packages/transports/http/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export default {
107107
options: {
108108
...payload.transportEntry.options,
109109
...payload.transportEntry.options?.subscriptions?.options,
110+
// Make sure to remove subscription option to avoid infinite loop.
111+
// This option doesn't make sense here but is present in `transportEntry.options`
112+
subscriptions: undefined,
110113
},
111114
}),
112115
(resolvedSubscriptionsExecutor) => {
Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { TransportEntry } from '@graphql-mesh/transport-common';
12
import type { MeshFetch } from '@graphql-mesh/types';
2-
import { buildSchema, parse } from 'graphql';
3+
import { buildSchema, OperationTypeNode, parse } from 'graphql';
34
import { describe, expect, it, vi } from 'vitest';
45
import httpTransport from '../src';
56

@@ -14,22 +15,25 @@ describe('HTTP Transport', () => {
1415
}),
1516
);
1617
const expectedToken = 'wowmuchsecret';
17-
const executor = httpTransport.getSubgraphExecutor({
18-
subgraphName,
19-
transportEntry: {
20-
kind: 'http',
21-
subgraph: subgraphName,
22-
headers: [['x-test', '{context.myToken}']],
23-
},
24-
fetch,
25-
// @ts-expect-error - transport kind is const in httpTransport but string is expected
26-
transportExecutorFactoryGetter: () => httpTransport.getSubgraphExecutor,
27-
subgraph: buildSchema(/* GraphQL */ `
28-
type Query {
29-
test: String
30-
}
31-
`),
18+
const getTransportExecutor = (transportEntry: TransportEntry) =>
19+
httpTransport.getSubgraphExecutor({
20+
subgraphName,
21+
transportEntry,
22+
fetch,
23+
getTransportExecutor,
24+
subgraph: buildSchema(/* GraphQL */ `
25+
type Query {
26+
test: String
27+
}
28+
`),
29+
});
30+
31+
const executor = getTransportExecutor({
32+
kind: 'http',
33+
subgraph: subgraphName,
34+
headers: [['x-test', '{context.myToken}']],
3235
});
36+
3337
await executor({
3438
document: parse(/* GraphQL */ `
3539
query {
@@ -46,4 +50,48 @@ describe('HTTP Transport', () => {
4650
},
4751
});
4852
});
53+
54+
it('should allow to specify subscription specific options', async () => {
55+
const fetch = vi.fn<MeshFetch>();
56+
57+
const getTransportExecutor = (transportEntry: TransportEntry) =>
58+
httpTransport.getSubgraphExecutor({
59+
subgraphName,
60+
transportEntry,
61+
fetch,
62+
getTransportExecutor,
63+
subgraph: buildSchema(/* GraphQL */ `
64+
type Subscription {
65+
test: String
66+
}
67+
`),
68+
});
69+
70+
const executor = getTransportExecutor({
71+
kind: 'http',
72+
subgraph: subgraphName,
73+
options: {
74+
subscriptions: {
75+
kind: 'http',
76+
subgraph: subgraphName,
77+
options: {
78+
method: 'POST',
79+
},
80+
},
81+
},
82+
});
83+
84+
await executor({
85+
operationType: OperationTypeNode.SUBSCRIPTION,
86+
document: parse(/* GraphQL */ `
87+
subscription {
88+
test
89+
}
90+
`),
91+
});
92+
93+
expect(fetch.mock.calls[0]?.[1]).toMatchObject({
94+
method: 'POST',
95+
});
96+
});
4997
});

0 commit comments

Comments
 (0)