Playing with Queries, and Playground
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"gen:types": "ts-node ./graphql/generate.typings",
|
||||
"prisma:gen": "prisma generate --watch",
|
||||
"dev": "concurrently \"yarn:start:dev\" \"yarn:gen:types\" \"yarn:prisma:gen\""
|
||||
"dev": "concurrently \"npm:start:dev\" \"npm:gen:types\" \"npm:prisma:gen\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/apollo": "^10.1.0",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "password" TEXT,
|
||||
ALTER COLUMN "time_joined" DROP NOT NULL;
|
||||
@@ -13,5 +13,6 @@ datasource db {
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
time_joined Int
|
||||
password String?
|
||||
time_joined Int?
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AuthModule } from './auth/auth.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { GraphQLISODateTime, GraphQLModule } from '@nestjs/graphql';
|
||||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||
// import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core';
|
||||
import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core';
|
||||
import { UsersModule } from './users/users.module';
|
||||
|
||||
@Module({
|
||||
@@ -25,9 +25,9 @@ import { UsersModule } from './users/users.module';
|
||||
driver: ApolloDriver,
|
||||
typePaths: ['./**/*.graphql'],
|
||||
debug: true,
|
||||
playground: true,
|
||||
resolvers: {DateTime: GraphQLISODateTime}
|
||||
// plugins: [ApolloServerPluginLandingPageLocalDefault()],
|
||||
playground: false,
|
||||
resolvers: { DateTime: GraphQLISODateTime },
|
||||
plugins: [ApolloServerPluginLandingPageLocalDefault()],
|
||||
}),
|
||||
UsersModule,
|
||||
],
|
||||
|
||||
@@ -16,7 +16,8 @@ export class CreateUserInput {
|
||||
export class User {
|
||||
id: string;
|
||||
email: string;
|
||||
time_joined: number;
|
||||
password?: Nullable<string>;
|
||||
time_joined?: Nullable<number>;
|
||||
}
|
||||
|
||||
export abstract class IQuery {
|
||||
|
||||
@@ -3,7 +3,8 @@ scalar DateTime
|
||||
type User {
|
||||
id: String!
|
||||
email: String!
|
||||
time_joined: Int!
|
||||
password: String
|
||||
time_joined: Int,
|
||||
}
|
||||
|
||||
input CreateUserInput {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Resolver, Query, Mutation, Args } from '@nestjs/graphql';
|
||||
import { CreateUserInput } from 'graphql/graphql.typings';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
@Resolver('User')
|
||||
@@ -7,12 +7,12 @@ export class UsersResolver {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@Mutation('createUser')
|
||||
// create(@Args('createUserInput') createUserInput: CreateUserInput) {
|
||||
// return this.usersService.create(createUserInput);
|
||||
// }
|
||||
create(@Args('createUserInput') createUserInput: Prisma.UserCreateInput) {
|
||||
return this.usersService.create(createUserInput);
|
||||
}
|
||||
@Query('users')
|
||||
findAll() {
|
||||
return this.usersService.users({});
|
||||
findAll(@Args('params') params: Prisma.UserFindManyArgs) {
|
||||
return this.usersService.users(params);
|
||||
}
|
||||
|
||||
@Query('user')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateUserInput } from 'graphql/graphql.typings';
|
||||
import { Prisma, User } from '@prisma/client';
|
||||
import { PrismaService } from 'prisma/prisma.service';
|
||||
|
||||
@@ -11,19 +10,13 @@ export class UsersService {
|
||||
return await this.prismaService.user.findUnique({ where: uniqueInput });
|
||||
}
|
||||
|
||||
async users(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
cursor?: Prisma.UserWhereUniqueInput;
|
||||
where?: Prisma.UserWhereInput;
|
||||
orderBy?: Prisma.UserOrderByWithRelationInput;
|
||||
}) {
|
||||
async users(params: Prisma.UserFindManyArgs) {
|
||||
return await this.prismaService.user.findMany(params);
|
||||
}
|
||||
|
||||
// create(createUserInput: CreateUserInput) {
|
||||
// return 'This action adds a new user';
|
||||
// }
|
||||
create(createUserInput: Prisma.UserCreateInput) {
|
||||
return this.prismaService.user.create({ data: createUserInput });
|
||||
}
|
||||
|
||||
// findAll() {
|
||||
// return `This action returns all users`;
|
||||
|
||||
Reference in New Issue
Block a user