feat: remove graphql due to complexity of stack #2
12
package.json
12
package.json
@ -14,30 +14,20 @@
|
||||
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('You must use Yarn to install, not NPM')\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/passport": "^3.0.1",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.3.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/graphql": "^12.2.1",
|
||||
"@nestjs/jwt": "^10.2.0",
|
||||
"@nestjs/mercurius": "^12.2.1",
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.4.11",
|
||||
"@nestjs/platform-fastify": "^10.4.9",
|
||||
"@prisma/client": "5.22.0",
|
||||
"axios": "^1.7.7",
|
||||
"graphql": "^16.9.0",
|
||||
"graphql-subscriptions": "^3.0.0",
|
||||
"graphql-tools": "^9.0.4",
|
||||
"graphql-ws": "^5.16.0",
|
||||
"mercurius": "14",
|
||||
"passport": "^0.7.0",
|
||||
"passport-discord": "^0.1.4",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"prisma": "^5.22.0",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"subscriptions-transport-ws": "^0.11.0"
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
|
@ -1,13 +1,10 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { JwtModule } from "@nestjs/jwt";
|
||||
import { GraphQLModule } from "@nestjs/graphql";
|
||||
import { MercuriusDriver, MercuriusDriverConfig } from "@nestjs/mercurius";
|
||||
|
||||
import { AppService } from "./app.service";
|
||||
import { UserModule } from "./user/user.module";
|
||||
|
||||
import { GraphqlOptions } from "./graphql/graphqlOptions";
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
|
||||
@Module({
|
||||
@ -19,10 +16,6 @@ import { AuthModule } from './auth/auth.module';
|
||||
global: true,
|
||||
secret: process.env.JWT_SECRET,
|
||||
}),
|
||||
// GraphQLModule.forRootAsync<MercuriusDriverConfig>({
|
||||
// driver: MercuriusDriver,
|
||||
// useClass: GraphqlOptions,
|
||||
// }),
|
||||
UserModule,
|
||||
AuthModule,
|
||||
],
|
||||
|
@ -1,46 +0,0 @@
|
||||
import { Injectable, UnauthorizedException } from "@nestjs/common";
|
||||
import { GqlOptionsFactory } from "@nestjs/graphql";
|
||||
import { JwtService } from "@nestjs/jwt";
|
||||
import { MercuriusDriverConfig } from "@nestjs/mercurius";
|
||||
|
||||
@Injectable()
|
||||
export class GraphqlOptions implements GqlOptionsFactory {
|
||||
constructor(private readonly jwtService: JwtService) {}
|
||||
|
||||
createGqlOptions(): Promise<MercuriusDriverConfig> | MercuriusDriverConfig {
|
||||
return {
|
||||
autoSchemaFile: "src/graphql/schema.gql",
|
||||
subscription: {
|
||||
context: (_connection, request) => {
|
||||
const authorization = request.headers.authorization;
|
||||
if (!authorization) throw new UnauthorizedException();
|
||||
|
||||
const token = authorization.split(" ")[1];
|
||||
if (!token) throw new UnauthorizedException();
|
||||
|
||||
try {
|
||||
const user = this.jwtService.verify(token);
|
||||
return { user };
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
},
|
||||
},
|
||||
graphiql: false,
|
||||
context: (req) => {
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) throw new UnauthorizedException();
|
||||
|
||||
const token = authorization.split(" ")[1];
|
||||
if (!token) throw new UnauthorizedException();
|
||||
|
||||
try {
|
||||
const user = this.jwtService.verify(token);
|
||||
return { user };
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
# ------------------------------------------------------
|
||||
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
|
||||
# ------------------------------------------------------
|
||||
|
||||
type User {
|
||||
id: String!
|
||||
username: String!
|
||||
isAdmin: Boolean!
|
||||
}
|
||||
|
||||
type Query {
|
||||
users: [User!]!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
CreateUser(createUserInput: CreateUserInput!): User!
|
||||
updateUser(updateUserInput: UpdateUserInput!): User!
|
||||
setPassword(setUserPasswordInput: SetUserPasswordInput!): User!
|
||||
}
|
||||
|
||||
input CreateUserInput {
|
||||
username: String!
|
||||
isAdmin: Boolean!
|
||||
}
|
||||
|
||||
input UpdateUserInput {
|
||||
username: String
|
||||
isAdmin: Boolean
|
||||
id: String!
|
||||
}
|
||||
|
||||
input SetUserPasswordInput {
|
||||
id: String!
|
||||
password: String!
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
userAdded: User!
|
||||
}
|
@ -1,10 +1,4 @@
|
||||
import { Field, InputType } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
export class CreateUserInput {
|
||||
@Field()
|
||||
username: string;
|
||||
|
||||
@Field()
|
||||
isAdmin: boolean;
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
import { Field, InputType } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
export class SetUserPasswordInput {
|
||||
@Field()
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
password: string;
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
import { Field, InputType, PartialType } from "@nestjs/graphql";
|
||||
import { CreateUserInput } from "./create-user.input";
|
||||
|
||||
@InputType()
|
||||
export class UpdateUserInput extends PartialType(CreateUserInput) {
|
||||
@Field()
|
||||
export class UpdateUserInput extends CreateUserInput {
|
||||
id: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
username: string;
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
import { Field, ObjectType } from "@nestjs/graphql";
|
||||
|
||||
@ObjectType()
|
||||
export class User {
|
||||
@Field(() => String)
|
||||
id: string;
|
||||
|
||||
@Field(() => String)
|
||||
username: string;
|
||||
|
||||
@Field(() => Boolean)
|
||||
isAdmin: boolean;
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
import { UserResolver } from "./user.resolver";
|
||||
import { UserService } from "./user.service";
|
||||
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
|
||||
@Module({
|
||||
providers: [UserResolver, UserService, PrismaService]
|
||||
providers: [UserService, PrismaService]
|
||||
})
|
||||
export class UserModule {}
|
||||
|
@ -1,56 +0,0 @@
|
||||
import {
|
||||
Args,
|
||||
Mutation,
|
||||
Query,
|
||||
Resolver,
|
||||
Subscription
|
||||
} from "@nestjs/graphql";
|
||||
|
||||
import { CreateUserInput } from "./dto/create-user.input";
|
||||
import { SetUserPasswordInput } from "./dto/setpassword-user.input";
|
||||
import { UpdateUserInput } from "./dto/update-user.input";
|
||||
import { User } from "./user.entity";
|
||||
import { UserService } from "./user.service";
|
||||
|
||||
import { PubSub } from "graphql-subscriptions";
|
||||
|
||||
const pubSub = new PubSub();
|
||||
|
||||
@Resolver(() => User)
|
||||
export class UserResolver {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Subscription(() => User)
|
||||
userAdded() {
|
||||
return pubSub.asyncIterableIterator<User>("userAdded");
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
async CreateUser(
|
||||
@Args("createUserInput") createUserInput: CreateUserInput,
|
||||
): Promise<User> {
|
||||
const user = await this.userService.create(createUserInput);
|
||||
pubSub.publish("userAdded", { userAdded: user });
|
||||
return user;
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
async updateUser(
|
||||
@Args("updateUserInput") updateUserInput: UpdateUserInput,
|
||||
) {
|
||||
return await this.userService.update(updateUserInput);
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
async setPassword(
|
||||
@Args("setUserPasswordInput")
|
||||
setUserPasswordInput: SetUserPasswordInput,
|
||||
) {
|
||||
return await this.userService.setPassword(setUserPasswordInput);
|
||||
}
|
||||
|
||||
@Query(() => [User])
|
||||
async users() {
|
||||
return await this.userService.findAll();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user