GraphQL
This commit is contained in:
+5
-1
@@ -24,13 +24,17 @@
|
|||||||
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
|
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@apollo/server": "^5.5.1",
|
||||||
|
"@as-integrations/express5": "^1.1.2",
|
||||||
|
"@nestjs/apollo": "^14.0.1",
|
||||||
"@nestjs/common": "^12.0.1",
|
"@nestjs/common": "^12.0.1",
|
||||||
"@nestjs/config": "^12.0.0",
|
|
||||||
"@nestjs/core": "^12.0.1",
|
"@nestjs/core": "^12.0.1",
|
||||||
|
"@nestjs/graphql": "^14.0.1",
|
||||||
"@nestjs/platform-express": "^12.0.1",
|
"@nestjs/platform-express": "^12.0.1",
|
||||||
"@prisma/adapter-pg": "^7.10.0",
|
"@prisma/adapter-pg": "^7.10.0",
|
||||||
"@prisma/client": "^7.10.0",
|
"@prisma/client": "^7.10.0",
|
||||||
"dotenv": "^18.0.1",
|
"dotenv": "^18.0.1",
|
||||||
|
"graphql": "^17.0.2",
|
||||||
"pg": "^8.23.0",
|
"pg": "^8.23.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
|
|||||||
Generated
+690
-29
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
allowBuilds:
|
allowBuilds:
|
||||||
|
'@apollo/protobufjs': true
|
||||||
'@prisma/engines': true
|
'@prisma/engines': true
|
||||||
esbuild: true
|
esbuild: true
|
||||||
prisma: true
|
prisma: true
|
||||||
|
|||||||
+15
-9
@@ -1,13 +1,19 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller.js';
|
import { GraphQLModule } from '@nestjs/graphql';
|
||||||
import { AppService } from './app.service.js';
|
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
|
||||||
|
import { PrismaModule } from './prisma/prisma.module.js';
|
||||||
|
import { ProfileModule } from './profile/profile.module.js';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule.forRoot({
|
imports: [
|
||||||
isGlobal: true,
|
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||||
})],
|
driver: ApolloDriver,
|
||||||
controllers: [],
|
autoSchemaFile: true,
|
||||||
providers: [],
|
}),
|
||||||
|
|
||||||
|
PrismaModule,
|
||||||
|
ProfileModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
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