-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dc5f21
commit a4f6359
Showing
27 changed files
with
2,964 additions
and
8,551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
dist | ||
tmp | ||
/out-tsc | ||
/apps/api/src/schema.gql | ||
|
||
# dependencies | ||
node_modules | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { GraphQLModule } from '@nestjs/graphql'; | ||
import * as path from 'path'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AuthModule } from '@kordis/api/auth'; | ||
|
||
import { AppResolver } from './app.resolver'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ConfigModule.forRoot({ isGlobal: true, cache: true })], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ | ||
ConfigModule.forRoot({ isGlobal: true, cache: true }), | ||
AuthModule, | ||
GraphQLModule.forRoot<ApolloDriverConfig>({ | ||
driver: ApolloDriver, | ||
autoSchemaFile: | ||
process.env.NODE_ENV !== 'production' | ||
? path.join(process.cwd(), 'apps/api/src/schema.gql') | ||
: true, | ||
subscriptions: { | ||
'graphql-ws': true, | ||
}, | ||
playground: process.env.NODE_ENV !== 'production', | ||
}), | ||
], | ||
providers: [AppService, AppResolver], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Test } from '@nestjs/testing'; | ||
|
||
import { AppResolver } from './app.resolver'; | ||
import { AppService } from './app.service'; | ||
|
||
describe('AppController', () => { | ||
let resolver: AppResolver; | ||
|
||
beforeEach(async () => { | ||
const app = await Test.createTestingModule({ | ||
controllers: [AppResolver], | ||
providers: [AppService], | ||
}).compile(); | ||
|
||
resolver = app.get<AppResolver>(AppResolver); | ||
}); | ||
|
||
describe('getData', () => { | ||
it('should return "Welcome to api!"', () => { | ||
expect(resolver.data()).toEqual({ message: 'Welcome to api!' }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Field, ObjectType, Query, Resolver } from '@nestjs/graphql'; | ||
|
||
import { AppService } from './app.service'; | ||
|
||
@ObjectType() | ||
export class AppData { | ||
@Field(() => String) | ||
message: string; | ||
} | ||
|
||
@Resolver(() => AppData) | ||
export class AppResolver { | ||
constructor(private appService: AppService) {} | ||
|
||
@Query(() => AppData) | ||
data(): AppData { | ||
return this.appService.getData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
const { composePlugins, withNx } = require('@nrwl/webpack'); | ||
|
||
// Nx plugins for webpack. | ||
module.exports = composePlugins(withNx(), (config) => { | ||
return config; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# ADR004: GraphQL Schema Generation Strategy | ||
|
||
## Status | ||
|
||
accepted | ||
|
||
## Context | ||
|
||
Apollo GraphQL offers 2 approaches to create and maintain a GraphQL schema: Code First and Schema First. We have to choose one of them to start developing our Graph. | ||
|
||
## Decision | ||
|
||
We are using the Code First approach which generates a GraphQL schema from TypeScript classes and their annotations. | ||
With the Code First approach, we have type safety out of the box and we can generate the schema automatically. | ||
Furthermore, the knowledge about GraphQL schema specifications is rare in the team, which also contributed to this decision. | ||
|
||
## Consequences | ||
|
||
- It is easier to setup, maintain and refactor. | ||
- We can think in TypeScript models and types while developing our schema, which should enable us to develop faster. | ||
- We might hit a barrier which we currently can not see with the Code First Approach when our schema gets complex. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { ExecutionContext, createParamDecorator } from '@nestjs/common'; | ||
import { GqlExecutionContext } from '@nestjs/graphql'; | ||
|
||
import { KordisRequest } from '@kordis/api/shared'; | ||
import { KordisGqlContext } from '@kordis/api/shared'; | ||
|
||
export const User = createParamDecorator((ctx: ExecutionContext) => { | ||
const { user } = ctx.switchToHttp().getRequest<KordisRequest>(); | ||
return user; | ||
export const User = createParamDecorator((_: never, ctx: ExecutionContext) => { | ||
const req = | ||
GqlExecutionContext.create(ctx).getContext<KordisGqlContext>().req; | ||
return req.user; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default as KordisRequest } from './lib/models/request.model'; | ||
export * from './lib/models/request.model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "api-test-helpers", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/api/test-helpers/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/api/test-helpers/**/*.ts"] | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createContextForRequest } from './lib/execution-context.test-helper'; | ||
export { createParamDecoratorFactory } from './lib/decorator.test-helper'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ROUTE_ARGS_METADATA } from '@nestjs/common/constants'; | ||
|
||
export function createParamDecoratorFactory( | ||
decorator: () => ParameterDecorator, | ||
) { | ||
class TestDecorator { | ||
public test(@decorator() value): void {} | ||
} | ||
|
||
const args = Reflect.getMetadata(ROUTE_ARGS_METADATA, TestDecorator, 'test'); | ||
return args[Object.keys(args)[0]].factory; | ||
} |
15 changes: 15 additions & 0 deletions
15
libs/api/test-helpers/src/lib/execution-context.test-helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { ExecutionContext } from '@nestjs/common'; | ||
|
||
import { KordisRequest } from '@kordis/api/shared'; | ||
|
||
export function createContextForRequest(req: KordisRequest) { | ||
return createMock<ExecutionContext>({ | ||
getArgs(): any[] { | ||
return [null, null, { req }, null]; | ||
}, | ||
getType(): string { | ||
return 'graphql'; | ||
}, | ||
}); | ||
} |
Oops, something went wrong.