Skip to content

Commit

Permalink
Hive Gateway Driver for NestJS
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 14, 2025
1 parent 06c6095 commit ca8c777
Show file tree
Hide file tree
Showing 13 changed files with 3,884 additions and 361 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-camels-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/nestjs': patch
---

Hive Gateway Driver for NestJS
8 changes: 8 additions & 0 deletions e2e/nestjs/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
35 changes: 35 additions & 0 deletions e2e/nestjs/nestjs.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
createExampleSetup,
createTenv,
getAvailablePort,
} from '@internal/e2e';
import { getLocalhost } from '@internal/testing';
import { fetch } from '@whatwg-node/fetch';
import { expect, it } from 'vitest';

const { spawn } = createTenv(__dirname);
const { supergraph, query, result } = createExampleSetup(__dirname);

it('executes the query', async () => {
const SUPERGRAPH = await supergraph();
const PORT = await getAvailablePort();
const [nest, waitForExit] = await spawn('yarn nest', {

Check failure on line 16 in e2e/nestjs/nestjs.e2e.ts

View workflow job for this annotation

GitHub Actions / Types

'nest' is declared but its value is never read.

Check failure on line 16 in e2e/nestjs/nestjs.e2e.ts

View workflow job for this annotation

GitHub Actions / Types

'waitForExit' is declared but its value is never read.
args: ['start'],
env: {
SUPERGRAPH,
PORT,
},
});
const hostname = await getLocalhost(PORT);
const response = await fetch(`${hostname}:${PORT}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
}),
});
const received = await response.json();
expect(received).toEqual(result);
});
39 changes: 39 additions & 0 deletions e2e/nestjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@e2e/nestjs",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "nest build",
"start": "nest start",
"start:debug": "nest start --debug --watch",
"start:dev": "nest start --watch",
"start:prod": "node dist/main"
},
"dependencies": {
"@graphql-hive/nestjs": "workspace:^",
"@nestjs/apollo": "^13.0.2",
"@nestjs/common": "^11.0.1",
"@nestjs/core": "^11.0.1",
"@nestjs/graphql": "^13.0.2",
"@nestjs/platform-express": "^11.0.1",
"graphql": "^16.10.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@swc/cli": "^0.6.0",
"@swc/core": "^1.10.7",
"@types/express": "^5.0.0",
"@types/node": "^22.10.7",
"globals": "^15.14.0",
"prettier": "^3.4.2",
"source-map-support": "^0.5.21",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3"
}
}
16 changes: 16 additions & 0 deletions e2e/nestjs/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
HiveGatewayDriver,
HiveGatewayDriverConfig,
} from '@graphql-hive/nestjs';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';

@Module({
imports: [
GraphQLModule.forRoot<HiveGatewayDriverConfig>({
driver: HiveGatewayDriver,
supergraph: process.env['SUPERGRAPH'] || './supergraph.graphql',
}),
],
})
export class AppModule {}
8 changes: 8 additions & 0 deletions e2e/nestjs/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
11 changes: 11 additions & 0 deletions e2e/nestjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env['PORT'] ?? 3000);
}
bootstrap().catch((e) => {
console.error(e);
process.exit(1);
});
4 changes: 4 additions & 0 deletions e2e/nestjs/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
21 changes: 21 additions & 0 deletions e2e/nestjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false,
"strictBindCallApply": false,
"noFallthroughCasesInSwitch": false
}
}
61 changes: 61 additions & 0 deletions packages/nestjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@graphql-hive/nestjs",
"version": "0.0.0",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/graphql-hive/gateway.git",
"directory": "packages/nestjs"
},
"homepage": "https://the-guild.dev/graphql/hive/docs/gateway",
"author": {
"email": "contact@the-guild.dev",
"name": "The Guild",
"url": "https://the-guild.dev"
},
"license": "MIT",
"engines": {
"node": ">=18.0.0"
},
"main": "./dist/index.js",
"exports": {
".": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./package.json": "./package.json"
},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "pkgroll --clean-dist",
"prepack": "yarn build"
},
"peerDependencies": {
"@nestjs/common": "^11.0.9",
"@nestjs/graphql": "^13.0.2",
"graphql": "^15.9.0 || ^16.9.0"
},
"dependencies": {
"@graphql-hive/gateway-runtime": "workspace:^",
"@graphql-mesh/types": "^0.103.6",
"@graphql-tools/utils": "^10.8.1",
"tslib": "^2.8.1"
},
"devDependencies": {
"@nestjs/common": "^11.0.9",
"@nestjs/graphql": "^13.0.2",
"fastify": "^5.2.1",
"graphql": "16.10.0",
"pkgroll": "2.10.0"
},
"sideEffects": false
}
Loading

0 comments on commit ca8c777

Please sign in to comment.