Added GraphQL api

This commit is contained in:
Bartosz Jarocki 2024-04-14 13:50:04 +02:00
parent 7b40b0b2ee
commit 27b6a8bd29
6 changed files with 1141 additions and 81 deletions

View File

@ -9,19 +9,26 @@
"lint": "next lint"
},
"dependencies": {
"@apollo/server": "^4.10.2",
"@as-integrations/next": "^3.0.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"@vercel/analytics": "^1.1.2",
"class-validator": "^0.14.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"graphql": "^16.8.1",
"graphql-scalars": "^1.23.0",
"lucide-react": "^0.300.0",
"next": "14.0.4",
"next": "14.2.1",
"react": "^18",
"react-dom": "^18",
"reflect-metadata": "^0.2.2",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7",
"type-graphql": "^2.0.0-beta.6",
"vaul": "^0.8.0"
},
"devDependencies": {

11
src/apollo/resolvers.ts Normal file
View File

@ -0,0 +1,11 @@
import { Resolver, Query } from "type-graphql";
import { Me } from "./type-defs";
import { RESUME_DATA } from "../data/resume-data";
@Resolver(() => Me)
export class MeResolver {
@Query(() => Me)
me(): Me {
return RESUME_DATA as any;
}
}

127
src/apollo/type-defs.ts Normal file
View File

@ -0,0 +1,127 @@
import { ObjectType, Field } from "type-graphql";
@ObjectType()
export class Social {
@Field(() => String)
name: string;
@Field(() => String)
url: string;
}
@ObjectType()
export class Contact {
@Field(() => String)
email: string;
@Field(() => String)
tel: string;
@Field(() => [Social])
social: Social[];
}
@ObjectType()
export class Education {
@Field(() => String)
school: string;
@Field(() => String)
degree: string;
@Field(() => String)
start: string;
@Field(() => String)
end: string;
}
@ObjectType()
export class Work {
@Field(() => String)
company: string;
@Field(() => String)
link: string;
@Field(() => [String])
badges: string[];
@Field(() => String)
title: string;
@Field(() => String)
start: string;
@Field(() => String)
end: string;
@Field(() => String)
description: string;
}
@ObjectType()
export class Link {
@Field(() => String)
label: string;
@Field(() => String)
href: string;
}
@ObjectType()
export class Project {
@Field(() => String)
title: string;
@Field(() => [String])
techStack: string[];
@Field(() => String)
description: string;
@Field(() => Link, { nullable: true })
link?: Link;
}
@ObjectType()
export class Me {
@Field(() => String)
name: string;
@Field(() => String)
initials: string;
@Field(() => String)
location: string;
@Field(() => String)
locationLink: string;
@Field(() => String)
about: string;
@Field(() => String)
summary: string;
@Field(() => String)
avatarUrl: string;
@Field(() => String)
personalWebsiteUrl: string;
@Field(() => Contact)
contact: Contact;
@Field(() => [Education])
education: Education[];
@Field(() => [Work])
work: Work[];
@Field(() => [String])
skills: string[];
@Field(() => [Project])
projects: Project[];
}

16
src/app/graphql/route.ts Normal file
View File

@ -0,0 +1,16 @@
import "reflect-metadata";
import { ApolloServer } from "@apollo/server";
import { startServerAndCreateNextHandler } from "@as-integrations/next";
import { MeResolver } from "../../apollo/resolvers";
import { buildSchema } from "type-graphql";
import { NextRequest } from "next/server";
const schema = await buildSchema({
resolvers: [MeResolver],
});
const apolloServer = new ApolloServer({ schema });
const handler = startServerAndCreateNextHandler<NextRequest>(apolloServer, {
context: async (req) => ({ req }),
});
export { handler as GET, handler as POST };

View File

@ -1,7 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2021",
"lib": ["dom", "dom.iterable", "esnext"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"skipLibCheck": true,
"strict": true,
@ -9,6 +11,7 @@
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"strictPropertyInitialization": false,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
@ -22,6 +25,12 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/images/logos/*.*"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"src/images/logos/*.*"
],
"exclude": ["node_modules"]
}

1046
yarn.lock

File diff suppressed because it is too large Load Diff