Skip to content

Commit a985671

Browse files
committed
Hive Gateway Driver for NestJS
1 parent b9e1abf commit a985671

File tree

9 files changed

+1522
-50
lines changed

9 files changed

+1522
-50
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',

packages/nestjs/package.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@graphql-hive/nestjs",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/graphql-hive/gateway.git",
8+
"directory": "packages/nestjs"
9+
},
10+
"homepage": "https://the-guild.dev/graphql/hive/docs/gateway",
11+
"author": {
12+
"email": "[email protected]",
13+
"name": "The Guild",
14+
"url": "https://the-guild.dev"
15+
},
16+
"license": "MIT",
17+
"engines": {
18+
"node": ">=18.0.0"
19+
},
20+
"main": "./dist/index.js",
21+
"exports": {
22+
".": {
23+
"require": {
24+
"types": "./dist/index.d.cts",
25+
"default": "./dist/index.cjs"
26+
},
27+
"import": {
28+
"types": "./dist/index.d.ts",
29+
"default": "./dist/index.js"
30+
}
31+
},
32+
"./package.json": "./package.json"
33+
},
34+
"types": "./dist/index.d.ts",
35+
"files": [
36+
"dist"
37+
],
38+
"scripts": {
39+
"build": "pkgroll --clean-dist",
40+
"prepack": "yarn build"
41+
},
42+
"peerDependencies": {
43+
"@nestjs/common": "^11.0.9",
44+
"@nestjs/graphql": "^13.0.2",
45+
"graphql": "^15.9.0 || ^16.9.0"
46+
},
47+
"dependencies": {
48+
"@graphql-hive/gateway-runtime": "workspace:^",
49+
"@graphql-mesh/types": "^0.103.18",
50+
"@graphql-tools/utils": "^10.8.1",
51+
"tslib": "^2.8.1"
52+
},
53+
"devDependencies": {
54+
"@nestjs/common": "11.0.9",
55+
"@nestjs/core": "11.0.9",
56+
"@nestjs/graphql": "13.0.2",
57+
"fastify": "5.2.1",
58+
"graphql": "^16.9.0",
59+
"pkgroll": "2.10.0",
60+
"reflect-metadata": "0.2.2",
61+
"rxjs": "7.8.1"
62+
},
63+
"sideEffects": false
64+
}

0 commit comments

Comments
 (0)