Skip to content

Commit ca8c777

Browse files
committed
Hive Gateway Driver for NestJS
1 parent 06c6095 commit ca8c777

File tree

13 files changed

+3884
-361
lines changed

13 files changed

+3884
-361
lines changed

.changeset/sixty-camels-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/nestjs': patch
3+
---
4+
5+
Hive Gateway Driver for NestJS

e2e/nestjs/nest-cli.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}

e2e/nestjs/nestjs.e2e.ts

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

e2e/nestjs/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@e2e/nestjs",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"build": "nest build",
7+
"start": "nest start",
8+
"start:debug": "nest start --debug --watch",
9+
"start:dev": "nest start --watch",
10+
"start:prod": "node dist/main"
11+
},
12+
"dependencies": {
13+
"@graphql-hive/nestjs": "workspace:^",
14+
"@nestjs/apollo": "^13.0.2",
15+
"@nestjs/common": "^11.0.1",
16+
"@nestjs/core": "^11.0.1",
17+
"@nestjs/graphql": "^13.0.2",
18+
"@nestjs/platform-express": "^11.0.1",
19+
"graphql": "^16.10.0",
20+
"reflect-metadata": "^0.2.2",
21+
"rxjs": "^7.8.1"
22+
},
23+
"devDependencies": {
24+
"@nestjs/cli": "^11.0.0",
25+
"@nestjs/schematics": "^11.0.0",
26+
"@nestjs/testing": "^11.0.1",
27+
"@swc/cli": "^0.6.0",
28+
"@swc/core": "^1.10.7",
29+
"@types/express": "^5.0.0",
30+
"@types/node": "^22.10.7",
31+
"globals": "^15.14.0",
32+
"prettier": "^3.4.2",
33+
"source-map-support": "^0.5.21",
34+
"ts-loader": "^9.5.2",
35+
"ts-node": "^10.9.2",
36+
"tsconfig-paths": "^4.2.0",
37+
"typescript": "^5.7.3"
38+
}
39+
}

e2e/nestjs/src/app.module.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
HiveGatewayDriver,
3+
HiveGatewayDriverConfig,
4+
} from '@graphql-hive/nestjs';
5+
import { Module } from '@nestjs/common';
6+
import { GraphQLModule } from '@nestjs/graphql';
7+
8+
@Module({
9+
imports: [
10+
GraphQLModule.forRoot<HiveGatewayDriverConfig>({
11+
driver: HiveGatewayDriver,
12+
supergraph: process.env['SUPERGRAPH'] || './supergraph.graphql',
13+
}),
14+
],
15+
})
16+
export class AppModule {}

e2e/nestjs/src/app.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class AppService {
5+
getHello(): string {
6+
return 'Hello World!';
7+
}
8+
}

e2e/nestjs/src/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
4+
async function bootstrap() {
5+
const app = await NestFactory.create(AppModule);
6+
await app.listen(process.env['PORT'] ?? 3000);
7+
}
8+
bootstrap().catch((e) => {
9+
console.error(e);
10+
process.exit(1);
11+
});

e2e/nestjs/tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4+
}

e2e/nestjs/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"declaration": true,
5+
"removeComments": true,
6+
"emitDecoratorMetadata": true,
7+
"experimentalDecorators": true,
8+
"allowSyntheticDefaultImports": true,
9+
"target": "ES2021",
10+
"sourceMap": true,
11+
"outDir": "./dist",
12+
"baseUrl": "./",
13+
"incremental": true,
14+
"skipLibCheck": true,
15+
"strictNullChecks": true,
16+
"forceConsistentCasingInFileNames": true,
17+
"noImplicitAny": false,
18+
"strictBindCallApply": false,
19+
"noFallthroughCasesInSwitch": false
20+
}
21+
}

packages/nestjs/package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.6",
50+
"@graphql-tools/utils": "^10.8.1",
51+
"tslib": "^2.8.1"
52+
},
53+
"devDependencies": {
54+
"@nestjs/common": "^11.0.9",
55+
"@nestjs/graphql": "^13.0.2",
56+
"fastify": "^5.2.1",
57+
"graphql": "16.10.0",
58+
"pkgroll": "2.10.0"
59+
},
60+
"sideEffects": false
61+
}

0 commit comments

Comments
 (0)