-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathfederation_integration_test.go
More file actions
532 lines (483 loc) · 20.1 KB
/
federation_integration_test.go
File metadata and controls
532 lines (483 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
package engine_test
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"path"
"regexp"
"strings"
"testing"
"time"
"github.com/jensneuse/abstractlogger"
"github.com/sebdah/goldie/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wundergraph/graphql-go-tools/execution/federationtesting"
"github.com/wundergraph/graphql-go-tools/execution/federationtesting/gateway"
)
func addGateway(enableART bool) func(setup *federationtesting.FederationSetup) *httptest.Server {
return func(setup *federationtesting.FederationSetup) *httptest.Server {
httpClient := http.DefaultClient
poller := gateway.NewDatasource([]gateway.ServiceConfig{
{Name: "accounts", URL: setup.AccountsUpstreamServer.URL},
{Name: "products", URL: setup.ProductsUpstreamServer.URL, WS: strings.ReplaceAll(setup.ProductsUpstreamServer.URL, "http:", "ws:")},
{Name: "reviews", URL: setup.ReviewsUpstreamServer.URL},
}, httpClient)
gtw := gateway.Handler(abstractlogger.NoopLogger, poller, httpClient, enableART)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
poller.Run(ctx)
return httptest.NewServer(gtw)
}
}
func testQueryPath(name string) string {
return path.Join("..", "federationtesting", "testdata", name)
}
func TestFederationIntegrationTestWithArt(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
setup := federationtesting.NewFederationSetup(addGateway(true))
defer setup.Close()
gqlClient := NewGraphqlClient(http.DefaultClient)
normalizeResponse := func(resp string) string {
rex, err := regexp.Compile(`http://127.0.0.1:\d+`)
require.NoError(t, err)
resp = rex.ReplaceAllString(resp, "http://localhost/graphql")
return resp
}
t.Run("single upstream query operation with ART", func(t *testing.T) {
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/complex_nesting.graphql"), nil, t)
respString := normalizeResponse(string(resp))
assert.Contains(t, respString, `{"data":{"me":{"id":"1234","username":"Me"`)
assert.Contains(t, respString, `"extensions":{"trace":{"version":"1","info":{"trace_start_time"`)
buf := &bytes.Buffer{}
_ = json.Indent(buf, []byte(respString), "", " ")
goldie.New(t, goldie.WithNameSuffix(".json")).Assert(t, "complex_nesting_query_with_art", buf.Bytes())
})
}
func TestFederationIntegrationTest(t *testing.T) {
t.Parallel()
// Shared setup for all read-only tests (minimizes open ports)
setup := federationtesting.NewFederationSetup(addGateway(false))
t.Cleanup(setup.Close)
gqlClient := NewGraphqlClient(http.DefaultClient)
t.Run("single upstream query operation", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/single_upstream.query"), nil, t)
assert.Equal(t, `{"data":{"me":{"id":"1234","username":"Me"}}}`, string(resp))
})
t.Run("query spans multiple federated servers", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/multiple_upstream.query"), nil, t)
assert.Equal(t, `{"data":{"topProducts":[{"name":"Trilby","reviews":[{"body":"A highly effective form of birth control.","author":{"username":"Me"}}]},{"name":"Fedora","reviews":[{"body":"Fedoras are one of the most fashionable hats around and can look great with a variety of outfits.","author":{"username":"Me"}}]}]}}`, string(resp))
})
// Mutation test needs its own setup because AddReview modifies the reviews resolver state
t.Run("mutation operation with variables", func(t *testing.T) {
t.Parallel()
mutSetup := federationtesting.NewFederationSetup(addGateway(false))
t.Cleanup(mutSetup.Close)
mutClient := NewGraphqlClient(http.DefaultClient)
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := mutClient.Query(ctx, mutSetup.GatewayServer.URL, testQueryPath("mutations/mutation_with_variables.query"), queryVariables{
"authorID": "3210",
"upc": "top-1",
"review": "This is the last straw. Hat you will wear. 11/10",
}, t)
assert.Equal(t, `{"data":{"addReview":{"body":"This is the last straw. Hat you will wear. 11/10","author":{"username":"User 3210"}}}}`, string(resp))
})
t.Run("union query", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/union.query"), nil, t)
assert.Equal(t, `{"data":{"me":{"username":"Me","history":[{"__typename":"Purchase","wallet":{"amount":123}},{"__typename":"Sale","rating":5},{"__typename":"Purchase","wallet":{"amount":123}}]}}}`, string(resp))
})
t.Run("interface query", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/interface.query"), nil, t)
assert.Equal(t, `{"data":{"me":{"username":"Me","history":[{"wallet":{"amount":123,"specialField1":"some special value 1"}},{"rating":5},{"wallet":{"amount":123,"specialField2":"some special value 2"}}]}}}`, string(resp))
})
t.Run("subscription query through WebSocket transport", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
wsAddr := strings.ReplaceAll(setup.GatewayServer.URL, "http://", "ws://")
messages := gqlClient.Subscription(ctx, wsAddr, testQueryPath("subscriptions/subscription.query"), queryVariables{
"upc": "top-1",
}, t)
assert.Equal(t, `{"id":"1","type":"data","payload":{"data":{"updateProductPrice":{"upc":"top-1","name":"Trilby","price":1}}}}`, string(<-messages))
assert.Equal(t, `{"id":"1","type":"data","payload":{"data":{"updateProductPrice":{"upc":"top-1","name":"Trilby","price":2}}}}`, string(<-messages))
})
t.Run("Multiple queries and nested fragments", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/multiple_queries_with_nested_fragments.query"), nil, t)
expected := `
{
"data": {
"topProducts": [
{
"__typename": "Product",
"price": 11,
"upc": "top-1"
},
{
"__typename": "Product",
"price": 22,
"upc": "top-2"
}
],
"me": {
"__typename": "User",
"id": "1234",
"username": "Me",
"reviews": [
{
"__typename": "Review",
"product": {
"__typename": "Product",
"price": 11,
"upc": "top-1"
}
},
{
"__typename": "Review",
"product": {
"__typename": "Product",
"price": 22,
"upc": "top-2"
}
}
]
}
}
}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Multiple queries with __typename", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/multiple_queries.query"), nil, t)
expected := `
{
"data": {
"topProducts": [
{
"__typename": "Product",
"price": 11,
"upc": "top-1"
},
{
"__typename": "Product",
"price": 22,
"upc": "top-2"
}
],
"me": {
"__typename": "User",
"id": "1234",
"username": "Me"
}
}
}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Query that returns union", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/multiple_queries_with_union_return.query"), nil, t)
expected := `
{
"data": {
"me": {
"__typename": "User",
"id": "1234",
"username": "Me"
},
"histories": [
{
"__typename": "Purchase",
"product": {
"__typename": "Product",
"upc": "top-1"
},
"wallet": {
"__typename": "WalletType1",
"currency": "USD"
}
},
{
"__typename": "Sale",
"product": {
"__typename": "Product",
"upc": "top-1"
},
"rating": 1
},
{
"__typename": "Purchase",
"product": {
"__typename": "Product",
"upc": "top-2"
},
"wallet": {
"__typename": "WalletType2",
"currency": "USD"
}
},
{
"__typename": "Sale",
"product": {
"__typename": "Product",
"upc": "top-2"
},
"rating": 2
},
{
"__typename": "Purchase",
"product": {
"__typename": "Product",
"upc": "top-3"
},
"wallet": {
"__typename": "WalletType2",
"currency": "USD"
}
},
{
"__typename": "Sale",
"product": {
"__typename": "Product",
"upc": "top-3"
},
"rating": 3
}
]
}
}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Object response type with interface and object fragment", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/interface_fragment_on_object.graphql"), nil, t)
expected := `
{
"data": {
"me": {
"id": "1234",
"username": "Me"
}
}
}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Interface response type with object fragment", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/object_fragment_on_interface.graphql"), nil, t)
expected := `
{
"data": {
"identifiable": {
"__typename": "User",
"id": "1234",
"username": "Me"
}
}
}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("recursive fragment", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.QueryStatusCode(ctx, setup.GatewayServer.URL, testQueryPath("queries/recursive_fragment.graphql"), nil, http.StatusInternalServerError, t)
assert.Len(t, resp, 0)
})
t.Run("empty fragment", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.QueryStatusCode(ctx, setup.GatewayServer.URL, testQueryPath("queries/empty_fragment.graphql"), nil, http.StatusInternalServerError, t)
assert.Len(t, resp, 0)
})
t.Run("empty fragment variant", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.QueryStatusCode(ctx, setup.GatewayServer.URL, testQueryPath("queries/empty_fragment_variant.graphql"), nil, http.StatusInternalServerError, t)
assert.Len(t, resp, 0)
})
t.Run("Union response type with interface fragments", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/interface_fragments_on_union.graphql"), nil, t)
expected := `
{
"data": {
"histories": [
{
"__typename": "Purchase",
"quantity": 1
},
{
"__typename": "Sale",
"location": "Germany"
},
{
"__typename": "Purchase",
"quantity": 2
},
{
"__typename": "Sale",
"location": "UK"
},
{
"__typename": "Purchase",
"quantity": 3
},
{
"__typename": "Sale",
"location": "Ukraine"
}
]
}
}`
assert.Equal(t, compact(expected), string(resp))
})
// This response data of this test returns location twice: from the interface selection and from the type fragment
// Duplicated properties (and therefore invalid JSON) are usually removed during normalization processes.
// It is not yet decided whether this should be addressed before these normalization processes.
t.Run("Complex nesting", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/complex_nesting.graphql"), nil, t)
expected := `{"data":{"me":{"id":"1234","username":"Me","history":[{"wallet":{"currency":"USD"}},{"location":"Germany","product":{"upc":"top-2","name":"Fedora"}},{"wallet":{"currency":"USD"}}],"reviews":[{"__typename":"Review","attachments":[{"__typename":"Question","body":"How do I turn it on?","upc":"top-1"}]},{"__typename":"Review","attachments":[{"__typename":"Rating","upc":"top-2","body":"The best hat I have ever bought in my life."},{"__typename":"Video","upc":"top-2","size":13.37}]}]}}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("More complex nesting", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/more_complex_nesting.graphql"), nil, t)
expected := `{"data":{"me":{"id":"1234","username":"Me","history":[{"wallet":{"currency":"USD"}},{"location":"Germany","product":{"upc":"top-2","name":"Fedora"}},{"wallet":{"currency":"USD"}}],"reviews":[{"__typename":"Review","attachments":[{"__typename":"Question","body":"How do I turn it on?","upc":"top-1"}],"comment":{"__typename":"Question","subject":"Life"}},{"__typename":"Review","attachments":[{"__typename":"Rating","upc":"top-2","body":"The best hat I have ever bought in my life."},{"__typename":"Video","upc":"top-2","size":13.37}],"comment":{"__typename":"Question","subject":"Life"}}]}}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Multiple nested interfaces", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/titlename.graphql"), nil, t)
expected := `{"data":{"titleName":{"__typename":"TitleName","title":"Title","a":"A","b":"B","name":"Name","c":"C"}}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Multiple nested unions", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/cd.graphql"), nil, t)
expected := `{"data":{"cds":[{"name":{"first":"Leonie","middle":"Johanna"}},{"name":{"first":"Jannik","last":"Neuse"}}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("More complex nesting typename variant", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/more_complex_nesting_typename_variant.graphql"), nil, t)
expected := `{"data":{"me":{"id":"1234","username":"Me","history":[{"wallet":{"currency":"USD"}},{"location":"Germany","product":{"upc":"top-2","name":"Fedora"}},{"wallet":{"currency":"USD"}}],"reviews":[{"__typename":"Review","attachments":[{"__typename":"Question","body":"How do I turn it on?","upc":"top-1"}]},{"__typename":"Review","attachments":[{"__typename":"Rating","upc":"top-2","body":"The best hat I have ever bought in my life."},{"__typename":"Video","upc":"top-2","size":13.37}]}]}}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract object", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/abstract_object.graphql"), nil, t)
expected := `{"data":{"otherInterfaces":[{"someObject":{"a":"A","b":"B"}},{"someObject":{"a":"AA","c":"CC"}},{"someObject":{"a":"AAA"}}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract object non shared", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/abstract_object_non_shared.graphql"), nil, t)
expected := `{"data":{"otherInterfaces":[{"someObject":{"a":"A"}},{"someObject":{"b":"BB"}},{"someObject":{"c":"CCC"}}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract object nested", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/abstract_object_nested.graphql"), nil, t)
expected := `{"data":{"someNestedInterfaces":[{"__typename":"SomeNestedType1","otherInterfaces":[{"__typename":"SomeType1","someObject":{"a":"1.A","c":"1.C","b":"1.B"}},{"__typename":"SomeType2","someObject":{"a":"1.AA","c":"1.CC"}},{"__typename":"SomeType3","someObject":{"a":"1.AAA"}}]},{"__typename":"SomeNestedType2","otherInterfaces":[{"__typename":"SomeType1","someObject":{"a":"2.A","c":"2.C","b":"2.B"}},{"__typename":"SomeType2","someObject":{"a":"2.AA","c":"2.CC"}},{"__typename":"SomeType3","someObject":{"a":"2.AAA"}}]}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract object nested reverse", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/abstract_object_nested_reverse.graphql"), nil, t)
expected := `{"data":{"someNestedInterfaces":[{"__typename":"SomeNestedType1","otherInterfaces":[{"someObject":{"a":"1.A","c":"1.C","b":"1.B"},"__typename":"SomeType1"},{"someObject":{"a":"1.AA","c":"1.CC"},"__typename":"SomeType2"},{"someObject":{"a":"1.AAA"},"__typename":"SomeType3"}]},{"__typename":"SomeNestedType2","otherInterfaces":[{"someObject":{"a":"2.A","c":"2.C","b":"2.B"},"__typename":"SomeType1"},{"someObject":{"a":"2.AA","c":"2.CC"},"__typename":"SomeType2"},{"someObject":{"a":"2.AAA"},"__typename":"SomeType3"}]}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract object mixed", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/abstract_object_mixed.graphql"), nil, t)
expected := `{"data":{"abstractList":[{},{"obj":{"names":["3","4"],"__typename":"SomeType2","height":2}}]}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Abstract interface field", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/ab.graphql"), nil, t)
expected := `{"data":{"interfaceUnion":{"__typename":"A","name":"A"}}}`
assert.Equal(t, compact(expected), string(resp))
})
t.Run("Merged fields are still resolved", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/merged_field.graphql"), nil, t)
expected := `{"data":{"cat":{"name":"Pepper"},"me":{"id":"1234","username":"Me","realName":"User Usington","reviews":[{"body":"A highly effective form of birth control."},{"body":"Fedoras are one of the most fashionable hats around and can look great with a variety of outfits."}],"history":[{},{"rating":5},{}]}}}`
assert.Equal(t, compact(expected), string(resp))
})
// Regression test for https://github.com/wundergraph/cosmo/issues/2346
// Deeply nested fields go missing when a named fragment on an interface
// contains inline fragments for multiple concrete types and the non-matching
// type's fragment is defined first.
t.Run("merge concrete type in root field and interface fragment", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
resp := gqlClient.Query(ctx, setup.GatewayServer.URL, testQueryPath("queries/merge_concrete_type_in_root_field_and_interface_fragment.graphql"), nil, t)
expected := `{"data":{"productA":{"category":{"id":"c111","displayOwner":{"name":"owner"}}}}}`
assert.Equal(t, compact(expected), string(resp))
})
}
func compact(input string) string {
var out bytes.Buffer
err := json.Compact(&out, []byte(input))
if err != nil {
return ""
}
return out.String()
}