Skip to content

Commit 357d931

Browse files
Hive Gateway tester and testing utilities (#1625)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 02d9ec4 commit 357d931

File tree

14 files changed

+766
-736
lines changed

14 files changed

+766
-736
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/plugin-aws-sigv4': patch
3+
---
4+
5+
dependencies updates:
6+
7+
- Updated dependency [`@aws-sdk/client-sts@^3.916.0` ↗︎](https://www.npmjs.com/package/@aws-sdk/client-sts/v/3.916.0) (from `^3.914.0`, in `dependencies`)

.changeset/dry-numbers-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/gateway-testing': major
3+
---
4+
5+
Hive Gateway tester and testing utilities

packages/plugins/aws-sigv4/tests/aws-sigv4-incoming.test.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { buildSubgraphSchema } from '@apollo/subgraph';
22
import { createInlineSigningKeyProvider, useJWT } from '@graphql-hive/gateway';
3-
import {
4-
createGatewayRuntime,
5-
useCustomFetch,
6-
} from '@graphql-hive/gateway-runtime';
7-
import { composeLocalSchemasWithApollo } from '@internal/testing';
3+
import { createGatewayTester } from '@graphql-hive/gateway-testing';
84
import { parse } from 'graphql';
9-
import { createYoga } from 'graphql-yoga';
105
import { describe, expect, it } from 'vitest';
116
import { useAWSSigv4 } from '../src';
127

@@ -23,18 +18,14 @@ describe('AWS Sigv4 Incoming requests', () => {
2318
},
2419
},
2520
});
26-
const subgraphServer = createYoga({
27-
schema: subgraphSchema,
28-
});
2921
it('validates incoming requests', async () => {
30-
await using gw = createGatewayRuntime({
31-
supergraph: composeLocalSchemasWithApollo([
22+
await using gw = createGatewayTester({
23+
subgraphs: [
3224
{
3325
name: 'subgraph',
3426
schema: subgraphSchema,
35-
url: 'http://localhost:4000/graphql',
3627
},
37-
]),
28+
],
3829
landingPage: false,
3930
graphqlEndpoint: '/',
4031
plugins: () => [
@@ -43,10 +34,6 @@ describe('AWS Sigv4 Incoming requests', () => {
4334
secretAccessKey: () => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
4435
},
4536
}),
46-
useCustomFetch(
47-
// @ts-expect-error - MeshFetch is not compatible with Yoga.fetch
48-
subgraphServer.fetch,
49-
),
5037
],
5138
});
5239
const response = await gw.fetch(
@@ -59,7 +46,7 @@ describe('AWS Sigv4 Incoming requests', () => {
5946
Date: 'Mon, 29 Dec 2015 00:00:00 GMT',
6047
'content-type': 'application/json',
6148
Host: 'sigv4examplegraphqlbucket.s3-eu-central-1.amazonaws.com',
62-
'Content-Length': 30,
49+
'Content-Length': '30',
6350
'X-Amz-Content-Sha256':
6451
'34c77dc7b593717e0231ac99a16ae3be5ee2e8d652bce6518738a6449dfd2647',
6552
'X-Amz-Date': '20151229T000000Z',
@@ -82,14 +69,13 @@ describe('AWS Sigv4 Incoming requests', () => {
8269
});
8370
it('works with JWT', async () => {
8471
const JWT_SECRET = 'a-string-secret-at-least-256-bits-long';
85-
await using gw = createGatewayRuntime({
86-
supergraph: composeLocalSchemasWithApollo([
72+
await using gw = createGatewayTester({
73+
subgraphs: [
8774
{
8875
name: 'subgraph',
8976
schema: subgraphSchema,
90-
url: 'http://localhost:4000/graphql',
9177
},
92-
]),
78+
],
9379
landingPage: false,
9480
graphqlEndpoint: '/',
9581
plugins: () => [
@@ -108,10 +94,6 @@ describe('AWS Sigv4 Incoming requests', () => {
10894
secretAccessKey: () => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
10995
},
11096
}),
111-
useCustomFetch(
112-
// @ts-expect-error - MeshFetch is not compatible with Yoga.fetch
113-
subgraphServer.fetch,
114-
),
11597
],
11698
});
11799

@@ -125,7 +107,7 @@ describe('AWS Sigv4 Incoming requests', () => {
125107
Date: 'Mon, 29 Dec 2015 00:00:00 GMT',
126108
'content-type': 'application/json',
127109
Host: 'sigv4examplegraphqlbucket.s3-eu-central-1.amazonaws.com',
128-
'Content-Length': 30,
110+
'Content-Length': '30',
129111
'X-Amz-Content-Sha256':
130112
'34c77dc7b593717e0231ac99a16ae3be5ee2e8d652bce6518738a6449dfd2647',
131113
'X-Amz-Date': '20151229T000000Z',

packages/plugins/aws-sigv4/tests/aws-sigv4-outgoing.test.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { buildSubgraphSchema } from '@apollo/subgraph';
2-
import {
3-
createGatewayRuntime,
4-
useCustomFetch,
5-
} from '@graphql-hive/gateway-runtime';
2+
import { createGatewayTester } from '@graphql-hive/gateway-testing';
63
import { useAWSSigv4 } from '@graphql-hive/plugin-aws-sigv4';
7-
import { composeLocalSchemasWithApollo } from '@internal/testing';
84
import { parse } from 'graphql';
9-
import { createYoga } from 'graphql-yoga';
105
import { describe, expect, it } from 'vitest';
116

127
describe('AWS Sigv4', () => {
@@ -24,26 +19,25 @@ describe('AWS Sigv4', () => {
2419
},
2520
});
2621
let receivedSubgraphRequest: Request | undefined;
27-
await using subgraphServer = createYoga({
28-
schema: subgraphSchema,
29-
plugins: [
30-
{
31-
onRequest({ request }) {
32-
receivedSubgraphRequest = request;
33-
},
34-
},
35-
],
36-
landingPage: false,
37-
graphqlEndpoint: '/',
38-
});
39-
await using gw = createGatewayRuntime({
40-
supergraph: await composeLocalSchemasWithApollo([
22+
await using gw = createGatewayTester({
23+
subgraphs: [
4124
{
4225
name: 'subgraph',
4326
schema: subgraphSchema,
44-
url: 'http://sigv4examplegraphqlbucket.s3-eu-central-1.amazonaws.com',
27+
host: 'sigv4examplegraphqlbucket.s3-eu-central-1.amazonaws.com',
28+
yoga: {
29+
plugins: [
30+
{
31+
onRequest({ request }) {
32+
receivedSubgraphRequest = request;
33+
},
34+
},
35+
],
36+
landingPage: false,
37+
graphqlEndpoint: '/',
38+
},
4539
},
46-
]),
40+
],
4741
transportEntries: {
4842
subgraph: {
4943
headers: [['Date', 'Mon, 29 Dec 2015 00:00:00 GMT']],
@@ -57,10 +51,6 @@ describe('AWS Sigv4', () => {
5751
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
5852
},
5953
}),
60-
useCustomFetch(
61-
// @ts-expect-error - MeshFetch is not compatible with Yoga.fetch
62-
subgraphServer.fetch,
63-
),
6454
],
6555
});
6656
const res = await gw.fetch('http://localhost:4000/graphql', {

0 commit comments

Comments
 (0)