Skip to content

Commit

Permalink
Merge pull request nestjs#1091 from cschroeter/master
Browse files Browse the repository at this point in the history
sample(prisma) update Prisma example
  • Loading branch information
kamilmysliwiec authored Sep 19, 2018
2 parents ce498e8 + 447372a commit 4d407ab
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 282 deletions.
219 changes: 0 additions & 219 deletions sample/22-graphql-prisma/graphql.schema.d.ts

This file was deleted.

10 changes: 5 additions & 5 deletions sample/22-graphql-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "5.3.6",
"@nestjs/core": "5.3.6",
"@nestjs/graphql": "5.2.2",
"@nestjs/common": "5.3.7",
"@nestjs/core": "5.3.7",
"@nestjs/graphql": "5.3.1",
"apollo-server-express": "2.0.6",
"graphql": "0.13.2",
"graphql-tools": "3.1.1",
"prisma": "1.15.3",
"prisma": "1.16.2",
"prisma-binding": "2.1.5",
"reflect-metadata": "0.1.12",
"rxjs": "6.3.2",
Expand All @@ -28,7 +28,7 @@
"nodemon": "1.18.4",
"prettier": "1.14.2",
"ts-node": "7.0.1",
"tsconfig-paths": "3.5.0",
"tsconfig-paths": "3.6.0",
"tslint": "5.11.0"
}
}
15 changes: 3 additions & 12 deletions sample/22-graphql-prisma/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';
import { PrismaModule } from './prisma/prisma.module';
import { PostsModule } from './posts/posts.module';
import { GraphqlOptions } from 'graphql.options';

@Module({
imports: [
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
path: '/',
installSubscriptionHandlers: true,
resolverValidationOptions: {
requireResolversForResolveType: false,
},
definitions: {
path: join(process.cwd(), 'src/graphql.schema.d.ts'),
outputAs: 'class',
},
GraphQLModule.forRootAsync({
useClass: GraphqlOptions,
}),
PrismaModule,
PostsModule,
Expand Down
21 changes: 21 additions & 0 deletions sample/22-graphql-prisma/src/graphql.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GqlOptionsFactory, GqlModuleOptions } from '@nestjs/graphql';
import { Injectable } from '@nestjs/common';
import { join } from 'path';

@Injectable()
export class GraphqlOptions implements GqlOptionsFactory {
createGqlOptions(): Promise<GqlModuleOptions> | GqlModuleOptions {
return {
typePaths: ['./**/*.graphql'],
path: '/',
installSubscriptionHandlers: true,
resolverValidationOptions: {
requireResolversForResolveType: false,
},
definitions: {
path: join(process.cwd(), 'src/graphql.schema.d.ts'),
outputAs: 'class',
},
};
}
}
29 changes: 15 additions & 14 deletions sample/22-graphql-prisma/src/graphql.schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ export class BatchPayload {
count: Long;
}

export class IMutation {
createPost(data: PostCreateInput): Post | Promise<Post>;
updatePost(data: PostUpdateInput, where: PostWhereUniqueInput): Post | Promise<Post>;
deletePost(where: PostWhereUniqueInput): Post | Promise<Post>;
upsertPost(where: PostWhereUniqueInput, create: PostCreateInput, update: PostUpdateInput): Post | Promise<Post>;
updateManyPosts(data: PostUpdateInput, where?: PostWhereInput): BatchPayload | Promise<BatchPayload>;
deleteManyPosts(where?: PostWhereInput): BatchPayload | Promise<BatchPayload>;
export abstract class IMutation {
abstract createPost(data: PostCreateInput): Post | Promise<Post>;
abstract updatePost(data: PostUpdateInput, where: PostWhereUniqueInput): Post | Promise<Post>;
abstract deletePost(where: PostWhereUniqueInput): Post | Promise<Post>;
abstract upsertPost(where: PostWhereUniqueInput, create: PostCreateInput, update: PostUpdateInput): Post | Promise<Post>;
abstract updateManyPosts(data: PostUpdateInput, where?: PostWhereInput): BatchPayload | Promise<BatchPayload>;
abstract deleteManyPosts(where?: PostWhereInput): BatchPayload | Promise<BatchPayload>;
}

export class PageInfo {
Expand Down Expand Up @@ -156,15 +156,16 @@ export class PostSubscriptionPayload {
previousValues?: PostPreviousValues;
}

export class IQuery {
posts(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): Post[] | Promise<Post[]>;
post(where: PostWhereUniqueInput): Post | Promise<Post>;
postsConnection(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): PostConnection | Promise<PostConnection>;
node(id: string): Node | Promise<Node>;
export abstract class IQuery {
abstract posts(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): Post[] | Promise<Post[]>;
abstract post(where: PostWhereUniqueInput): Post | Promise<Post>;
abstract postsConnection(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): PostConnection | Promise<PostConnection>;
abstract node(id: string): Node | Promise<Node>;
abstract temp__(): boolean | Promise<boolean>;
}

export class ISubscription {
post(where?: PostSubscriptionWhereInput): PostSubscriptionPayload | Promise<PostSubscriptionPayload>;
export abstract class ISubscription {
abstract post(where?: PostSubscriptionWhereInput): PostSubscriptionPayload | Promise<PostSubscriptionPayload>;
}

export class User {
Expand Down
21 changes: 21 additions & 0 deletions sample/22-graphql-prisma/src/posts/posts.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Info,
} from '@nestjs/graphql';
import { PrismaService } from '../prisma/prisma.service';
import { BatchPayload } from '../prisma/prisma.binding';
import { Post } from '../graphql.schema';

@Resolver()
Expand All @@ -28,6 +29,26 @@ export class PostsResolver {
return await this.prisma.mutation.createPost(args, info);
}

@Mutation('updatePost')
async updatePost(@Args() args, @Info() info): Promise<Post> {
return await this.prisma.mutation.updatePost(args, info);
}

@Mutation('updateManyPosts')
async updateManyPosts(@Args() args, @Info() info): Promise<BatchPayload> {
return await this.prisma.mutation.updateManyPosts(args, info);
}

@Mutation('deletePost')
async deletePost(@Args() args, @Info() info): Promise<Post> {
return await this.prisma.mutation.deletePost(args, info);
}

@Mutation('deleteManyPosts')
async deleteManyPosts(@Args() args, @Info() info): Promise<BatchPayload> {
return await this.prisma.mutation.deleteManyPosts(args, info);
}

@Subscription('post')
onUserMutation() {
return {
Expand Down
Loading

0 comments on commit 4d407ab

Please sign in to comment.