query database in hello resolver

This commit is contained in:
Moriz Wahl 2023-12-07 11:29:30 +01:00
parent a1b8bae45a
commit 6b27b89890
3 changed files with 18 additions and 7 deletions

View File

@ -1,11 +1,13 @@
import { Resolver, Query } from 'type-graphql'
import { prisma } from '#src/prisma'
import { Hello } from '#types/Hello'
@Resolver()
export class HelloResolver {
@Query(() => Hello)
async hello(): Promise<Hello> {
return new Hello('Hello world!')
const data = await prisma.hello.findFirst()
return new Hello(data?.text ?? 'Hello World!')
}
}

View File

@ -1,15 +1,21 @@
// eslint-disable-next-line import/no-unassigned-import
import 'reflect-metadata'
import { prisma } from './prisma'
import { listen } from './server/server'
export async function main() {
export const main = async (): Promise<void> => {
const url = await listen(4000)
// eslint-disable-next-line no-console
console.log(`🚀 Server is ready at ${url}`)
}
main().catch((e) => {
// eslint-disable-next-line promise/catch-or-return
main()
.catch((e) => {
// eslint-disable-next-line no-console
console.error(e)
throw e
})
.finally(async () => {
await prisma.$disconnect()
})

3
src/prisma.ts Normal file
View File

@ -0,0 +1,3 @@
import { PrismaClient } from '@prisma/client'
export const prisma = new PrismaClient()