1
+ import { TransportEntry } from '@graphql-mesh/transport-common' ;
1
2
import type { MeshFetch } from '@graphql-mesh/types' ;
2
- import { buildSchema , parse } from 'graphql' ;
3
+ import { buildSchema , OperationTypeNode , parse } from 'graphql' ;
3
4
import { describe , expect , it , vi } from 'vitest' ;
4
5
import httpTransport from '../src' ;
5
6
@@ -14,22 +15,25 @@ describe('HTTP Transport', () => {
14
15
} ) ,
15
16
) ;
16
17
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}' ] ] ,
32
35
} ) ;
36
+
33
37
await executor ( {
34
38
document : parse ( /* GraphQL */ `
35
39
query {
@@ -46,4 +50,48 @@ describe('HTTP Transport', () => {
46
50
} ,
47
51
} ) ;
48
52
} ) ;
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
+ } ) ;
49
97
} ) ;
0 commit comments