@@ -6,7 +6,7 @@ import { makeExecutableSchema } from '@graphql-tools/schema';
6
6
import { stitchSchemas , ValidationLevel } from '@graphql-tools/stitch' ;
7
7
import { assertAsyncIterable } from '../../testing/utils' ;
8
8
9
- it ( 'should resolve missing fields from subgraphs on subscription event' , async ( ) => {
9
+ it ( 'should resolve fields from subgraphs on subscription event' , async ( ) => {
10
10
const products = makeExecutableSchema ( {
11
11
typeDefs : parse ( /* GraphQL */ `
12
12
type Query {
@@ -99,3 +99,103 @@ it('should resolve missing fields from subgraphs on subscription event', async (
99
99
}
100
100
` ) ;
101
101
} ) ;
102
+
103
+ // TODO: we skip because this test will fail, we need to optimize the resolver to account for available fields
104
+ it . skip ( 'should resolve only missing fields from subgraphs on subscription event' , async ( ) => {
105
+ const productPriceResolver = jest . fn ( ( ) => 100 ) ;
106
+ const products = makeExecutableSchema ( {
107
+ typeDefs : parse ( /* GraphQL */ `
108
+ type Query {
109
+ productById(id: ID!): Product
110
+ }
111
+ type Product {
112
+ id: ID!
113
+ name: String!
114
+ price: Float!
115
+ }
116
+ ` ) ,
117
+ resolvers : {
118
+ Query : {
119
+ productById : ( _ , { id } ) => ( {
120
+ id,
121
+ name : `Roomba X${ id } ` ,
122
+ } ) ,
123
+ } ,
124
+ Product : {
125
+ price : productPriceResolver ,
126
+ } ,
127
+ } ,
128
+ } ) ;
129
+
130
+ await using pubsub = new MemPubSub ( ) ;
131
+ const additionalTypeDefs = parse ( /* GraphQL */ `
132
+ extend schema {
133
+ subscription: Subscription
134
+ }
135
+ type Subscription {
136
+ newProduct: Product!
137
+ }
138
+ ` ) ;
139
+ const additionalResolvers = resolveAdditionalResolversWithoutImport (
140
+ {
141
+ targetTypeName : 'Subscription' ,
142
+ targetFieldName : 'newProduct' ,
143
+ pubsubTopic : 'new_product' ,
144
+ } ,
145
+ pubsub ,
146
+ ) ;
147
+
148
+ const stitched = stitchSchemas ( {
149
+ subschemas : [
150
+ {
151
+ schema : products ,
152
+ merge : {
153
+ Product : {
154
+ selectionSet : '{ id }' ,
155
+ fieldName : 'productById' ,
156
+ args : ( { id } ) => ( { id } ) ,
157
+ } ,
158
+ } ,
159
+ } ,
160
+ ] ,
161
+ typeDefs : additionalTypeDefs ,
162
+ resolvers : additionalResolvers ,
163
+ } ) ;
164
+
165
+ const result = await subscribe ( {
166
+ schema : stitched ,
167
+ document : parse ( /* GraphQL */ `
168
+ subscription {
169
+ newProduct {
170
+ name
171
+ ...P
172
+ }
173
+ }
174
+ fragment P on Product {
175
+ price
176
+ }
177
+ ` ) ,
178
+ } ) ;
179
+ assertAsyncIterable ( result ) ;
180
+ const iter = result [ Symbol . asyncIterator ] ( ) ;
181
+
182
+ setTimeout ( ( ) => {
183
+ pubsub . publish ( 'new_product' , { id : '60' , price : 999 } ) ;
184
+ } , 0 ) ;
185
+
186
+ await expect ( iter . next ( ) ) . resolves . toMatchInlineSnapshot ( `
187
+ {
188
+ "done": false,
189
+ "value": {
190
+ "data": {
191
+ "newProduct": {
192
+ "name": "Roomba X60",
193
+ "price": 999,
194
+ },
195
+ },
196
+ },
197
+ }
198
+ ` ) ;
199
+
200
+ expect ( productPriceResolver ) . not . toHaveBeenCalled ( ) ;
201
+ } ) ;
0 commit comments