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