Skip to content

Commit 4ecd48f

Browse files
committed
Hive Gateway Driver for NestJS
1 parent 6cc87c6 commit 4ecd48f

File tree

8 files changed

+813
-33
lines changed

8 files changed

+813
-33
lines changed

.changeset/sixty-camels-design.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/nestjs': patch
3+
---
4+
5+
Hive Gateway Driver for NestJS;
6+
7+
[Learn more in the docs](https://the-guild.dev/graphql/hive/docs/gateway/deployment/node-frameworks/nestjs)

e2e/nestjs/nestjs.e2e.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createExampleSetup, createTenv } from '@internal/e2e';
2+
import { getLocalhost } from '@internal/testing';
3+
import { fetch } from '@whatwg-node/fetch';
4+
import { expect, it } from 'vitest';
5+
6+
const { service } = createTenv(__dirname);
7+
const { supergraph, query, result } = createExampleSetup(__dirname);
8+
9+
it('executes the query', async () => {
10+
const supergraphPath = await supergraph();
11+
const { port } = await service('nestjs', {
12+
args: [`--supergraph=${supergraphPath}`],
13+
});
14+
const hostname = await getLocalhost(port);
15+
const response = await fetch(`${hostname}:${port}/graphql`, {
16+
method: 'POST',
17+
headers: {
18+
'Content-Type': 'application/json',
19+
},
20+
body: JSON.stringify({
21+
query,
22+
}),
23+
});
24+
const received = await response.json();
25+
expect(received).toEqual(result);
26+
});

e2e/nestjs/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@e2e/nestjs",
3+
"version": "0.0.1",
4+
"private": true,
5+
"dependencies": {
6+
"@graphql-hive/nestjs": "workspace:^",
7+
"@nestjs/common": "^11.0.1",
8+
"@nestjs/core": "^11.0.9",
9+
"@nestjs/graphql": "^13.0.2",
10+
"@nestjs/platform-express": "^11.0.9",
11+
"graphql": "^16.10.0",
12+
"reflect-metadata": "^0.2.2",
13+
"rxjs": "^7.8.1"
14+
}
15+
}

e2e/nestjs/services/nestjs.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
HiveGatewayDriver,
3+
HiveGatewayDriverConfig,
4+
} from '@graphql-hive/nestjs';
5+
import { Opts } from '@internal/testing';
6+
import { Module } from '@nestjs/common';
7+
import { NestFactory } from '@nestjs/core';
8+
import { GraphQLModule } from '@nestjs/graphql';
9+
10+
const opts = Opts(process.argv);
11+
const supergraph = opts.get('supergraph', true);
12+
13+
@Module({
14+
imports: [
15+
GraphQLModule.forRoot<HiveGatewayDriverConfig>({
16+
driver: HiveGatewayDriver,
17+
supergraph,
18+
}),
19+
],
20+
})
21+
class AppModule {}
22+
23+
const port = opts.getServicePort('nestjs', true);
24+
25+
async function main() {
26+
const app = await NestFactory.create(AppModule);
27+
await app.listen(port);
28+
}
29+
30+
main().catch((err) => {
31+
console.error(err);
32+
process.exit(1);
33+
});

internal/e2e/src/tenv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ export function createTenv(cwd: string): Tenv {
691691
pipeLogs = isDebug(),
692692
args = [],
693693
protocol = 'http',
694+
env,
694695
} = {},
695696
) {
696697
port ||= await getAvailablePort();
@@ -702,6 +703,7 @@ export function createTenv(cwd: string): Tenv {
702703
signal: ctrl.signal,
703704
stack: leftoverStack,
704705
replaceStderr: (str) => str.replaceAll(__project, ''),
706+
env,
705707
},
706708
'node',
707709
'--import',

0 commit comments

Comments
 (0)