Skip to content

Commit

Permalink
create userquery
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity2701 committed Jul 11, 2024
1 parent bec0861 commit 78214e2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions backend/src/graphql/models/UserModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { User as DbUser } from '@prisma/client'
import { ObjectType, Field, Int } from 'type-graphql'

@ObjectType()
export class User {
constructor(user: DbUser) {
this.id = user.id
this.username = user.username
this.name = user.name
}

@Field(() => Int)
id: number

@Field()
username: string

@Field()
name: string
}
12 changes: 12 additions & 0 deletions backend/src/graphql/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Resolver, Query } from 'type-graphql'

import { User } from '#graphql/models/UserModel'
import { prisma } from '#src/prisma'

@Resolver()
export class UserResolver {
@Query(() => [User])
async users(): Promise<User[]> {
return prisma.user.findMany()
}
}
3 changes: 2 additions & 1 deletion backend/src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { ContactFormResolver } from './resolvers/ContactFormResolver'
import { checkForOpenRooms } from './resolvers/dal/handleOpenRooms'
import { NewsletterSubscriptionResolver } from './resolvers/NewsletterSubscriptionResolver'
import { RoomResolver } from './resolvers/RoomResolver'
import { UserResolver } from './resolvers/UserResolver'

if (CONFIG.BBB_PULL_MEETINGS) void checkForOpenRooms()

export const schema = async (): Promise<GraphQLSchema> => {
return buildSchema({
resolvers: [ContactFormResolver, NewsletterSubscriptionResolver, RoomResolver],
resolvers: [ContactFormResolver, NewsletterSubscriptionResolver, RoomResolver, UserResolver],
pubSub,
validate: {
validationError: { target: false },
Expand Down

0 comments on commit 78214e2

Please sign in to comment.