GraphQL
This commit is contained in:
+5
-1
@@ -24,13 +24,17 @@
|
||||
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/server": "^5.5.1",
|
||||
"@as-integrations/express5": "^1.1.2",
|
||||
"@nestjs/apollo": "^14.0.1",
|
||||
"@nestjs/common": "^12.0.1",
|
||||
"@nestjs/config": "^12.0.0",
|
||||
"@nestjs/core": "^12.0.1",
|
||||
"@nestjs/graphql": "^14.0.1",
|
||||
"@nestjs/platform-express": "^12.0.1",
|
||||
"@prisma/adapter-pg": "^7.10.0",
|
||||
"@prisma/client": "^7.10.0",
|
||||
"dotenv": "^18.0.1",
|
||||
"graphql": "^17.0.2",
|
||||
"pg": "^8.23.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
|
||||
Generated
+690
-29
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
allowBuilds:
|
||||
'@apollo/protobufjs': true
|
||||
'@prisma/engines': true
|
||||
esbuild: true
|
||||
prisma: true
|
||||
|
||||
+14
-8
@@ -1,13 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller.js';
|
||||
import { AppService } from './app.service.js';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||
|
||||
import { PrismaModule } from './prisma/prisma.module.js';
|
||||
import { ProfileModule } from './profile/profile.module.js';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
})],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
imports: [
|
||||
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||
driver: ApolloDriver,
|
||||
autoSchemaFile: true,
|
||||
}),
|
||||
|
||||
PrismaModule,
|
||||
ProfileModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
|
||||
import { PrismaService } from './prisma.service.js';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService],
|
||||
})
|
||||
export class PrismaModule {}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
|
||||
import { PrismaClient } from '../generated/prisma/client.js';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService
|
||||
extends PrismaClient
|
||||
implements OnModuleDestroy
|
||||
{
|
||||
constructor() {
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
|
||||
if (!connectionString) {
|
||||
throw new Error('DATABASE_URL is required');
|
||||
}
|
||||
|
||||
const adapter = new PrismaPg({
|
||||
connectionString,
|
||||
});
|
||||
|
||||
super({ adapter });
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Experience {
|
||||
@Field(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
company: string;
|
||||
|
||||
@Field()
|
||||
position: string;
|
||||
|
||||
@Field(() => Date)
|
||||
startDate: Date;
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
endDate: Date | null;
|
||||
|
||||
@Field(() => [String])
|
||||
achievements: string[];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Link {
|
||||
@Field(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
name: string;
|
||||
|
||||
@Field()
|
||||
url: string;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { Experience } from './experience.model.js';
|
||||
import { Link } from './link.model.js';
|
||||
import { Project } from './project.model.js';
|
||||
import { Skill } from './skill.model.js';
|
||||
|
||||
@ObjectType()
|
||||
export class Profile {
|
||||
@Field(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
name: string;
|
||||
|
||||
@Field()
|
||||
description: string;
|
||||
|
||||
@Field(() => [Link])
|
||||
links: Link[];
|
||||
|
||||
@Field(() => [Skill])
|
||||
skills: Skill[];
|
||||
|
||||
@Field(() => [Experience])
|
||||
experience: Experience[];
|
||||
|
||||
@Field(() => [Project])
|
||||
projects: Project[];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Project {
|
||||
@Field(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
name: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
url: string | null;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
description: string | null;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Skill {
|
||||
@Field(() => ID)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { ProfileResolver } from './profile.resolver.js';
|
||||
import { ProfileService } from './profile.service.js';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
ProfileResolver,
|
||||
ProfileService,
|
||||
],
|
||||
})
|
||||
export class ProfileModule {}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { Profile } from './models/profile.model.js';
|
||||
import { ProfileService } from './profile.service.js';
|
||||
|
||||
@Resolver(() => Profile)
|
||||
export class ProfileResolver {
|
||||
constructor(
|
||||
private readonly profileService: ProfileService,
|
||||
) {}
|
||||
|
||||
@Query(() => Profile, { nullable: true })
|
||||
profile() {
|
||||
return this.profileService.getProfile();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service.js';
|
||||
|
||||
@Injectable()
|
||||
export class ProfileService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
|
||||
getProfile() {
|
||||
return this.prisma.profile.findFirst({
|
||||
include: {
|
||||
links: true,
|
||||
skills: true,
|
||||
experience: true,
|
||||
projects: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user