mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
sample(): upgrade sample 22-graphql-prisma
This commit is contained in:
0
sample/22-graphql-prisma/.eslintrc.js
Normal file → Executable file
0
sample/22-graphql-prisma/.eslintrc.js
Normal file → Executable file
117
sample/22-graphql-prisma/.gitignore
vendored
Normal file → Executable file
117
sample/22-graphql-prisma/.gitignore
vendored
Normal file → Executable file
@@ -1,104 +1,27 @@
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# Created by https://www.gitignore.io/api/node,macos,visualstudiocode
|
||||
# IDE
|
||||
/.idea
|
||||
/.awcache
|
||||
/.vscode
|
||||
|
||||
### macOS ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
# misc
|
||||
npm-debug.log
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
# example
|
||||
/quick-start
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
# tests
|
||||
/test
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
# dist
|
||||
/dist
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
# database
|
||||
prisma/dev.db
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history
|
||||
|
||||
|
||||
# Target Folder
|
||||
dist/
|
||||
*.deb
|
||||
|
||||
# End of https://www.gitignore.io/api/node,macos,visualstudiocode
|
||||
# secrets
|
||||
.env
|
||||
@@ -1,11 +0,0 @@
|
||||
projects:
|
||||
database:
|
||||
schemaPath: src/prisma/prisma-types.graphql
|
||||
extensions:
|
||||
endpoints:
|
||||
default: https://eu1.prisma.sh/public-agatepuma-476/my-app/dev
|
||||
codegen:
|
||||
- generator: prisma-binding
|
||||
language: typescript
|
||||
output:
|
||||
binding: src/prisma/prisma.binding.ts
|
||||
14
sample/22-graphql-prisma/README.md
Executable file
14
sample/22-graphql-prisma/README.md
Executable file
@@ -0,0 +1,14 @@
|
||||
### Prisma GraphQL schema first sample
|
||||
|
||||
This sample project uses sqlite as the relational database. To use a different database, check the [Prisma docs](https://www.prisma.io/docs/getting-started).
|
||||
|
||||
### Installation
|
||||
|
||||
1. Install dependencies: `npm install`
|
||||
2. Generate TypeScript type definitions for the GraphQL schema: `npm run generate:typings`
|
||||
3. Create sqlite database and create tables: `npx prisma db push`
|
||||
4. Start server: `npm run start:dev`
|
||||
|
||||
### Graphql Playground
|
||||
|
||||
When the application is running, you can go to [http://localhost:3000/graphql](http://localhost:3000/graphql) to access the GraphQL Playground. See [here](https://docs.nestjs.com/graphql/quick-start#playground) for more.
|
||||
@@ -1,6 +0,0 @@
|
||||
type Post {
|
||||
id: ID! @unique @id
|
||||
isPublished: Boolean! @default(value: false)
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
# The endpoint of your Prisma API (deployed to a Prisma Sandbox).
|
||||
endpoint: https://eu1.prisma.sh/public-agatepuma-476/my-app/dev
|
||||
|
||||
# The file containing the definition of your data model.
|
||||
datamodel: datamodel.graphql
|
||||
|
||||
# Seed your service with initial data based on `seed.graphql`.
|
||||
seed:
|
||||
import: seed.graphql
|
||||
|
||||
# Download the GraphQL schema of the Prisma API into
|
||||
# `src/generated/prisma.graphql` (as specfied in `.graphqlconfig.yml`).
|
||||
hooks:
|
||||
post-deploy:
|
||||
- graphql get-schema --project database
|
||||
|
||||
# If specified, the `secret` must be used to generate a JWT which is attached
|
||||
# to the `Authorization` header of HTTP requests made against the Prisma API.
|
||||
# Info: https://www.prisma.io/docs/reference/prisma-api/concepts-utee3eiquo#authentication
|
||||
# secret: mysecret123
|
||||
@@ -1,31 +0,0 @@
|
||||
mutation {
|
||||
first: createPost(
|
||||
data: {
|
||||
title: "Hello World 👋"
|
||||
text: "I like turtles."
|
||||
isPublished: true
|
||||
}
|
||||
) {
|
||||
id
|
||||
}
|
||||
|
||||
second: createPost(
|
||||
data: {
|
||||
title: "Join us at GraphQL Europe 🇪🇺 "
|
||||
text: "Get a 10%-discount with this promo code on graphql-europe.org: gql-boilerplates"
|
||||
isPublished: true
|
||||
}
|
||||
) {
|
||||
id
|
||||
}
|
||||
|
||||
third: createPost(
|
||||
data: {
|
||||
title: "Solving world hunger"
|
||||
text: "This is a draft..."
|
||||
isPublished: false
|
||||
}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
9
sample/22-graphql-prisma/generate-typings.ts
Executable file
9
sample/22-graphql-prisma/generate-typings.ts
Executable file
@@ -0,0 +1,9 @@
|
||||
import { GraphQLDefinitionsFactory } from '@nestjs/graphql';
|
||||
import { join } from 'path';
|
||||
|
||||
const definitionsFactory = new GraphQLDefinitionsFactory();
|
||||
definitionsFactory.generate({
|
||||
typePaths: ['./src/**/*.graphql'],
|
||||
path: join(process.cwd(), 'src/graphql.schema.ts'),
|
||||
outputAs: 'class',
|
||||
});
|
||||
5
sample/22-graphql-prisma/nest-cli.json
Executable file
5
sample/22-graphql-prisma/nest-cli.json
Executable file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"assets": ["**/*.graphql"]
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"watch": ["src"],
|
||||
"ext": "ts",
|
||||
"ignore": ["src/**/*.spec.ts", "src/graphql.schema.d.ts"],
|
||||
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
|
||||
}
|
||||
20702
sample/22-graphql-prisma/package-lock.json
generated
20702
sample/22-graphql-prisma/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
60
sample/22-graphql-prisma/package.json
Normal file → Executable file
60
sample/22-graphql-prisma/package.json
Normal file → Executable file
@@ -6,6 +6,7 @@
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "nest build",
|
||||
"generate:typings": "ts-node generate-typings.ts",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
@@ -19,38 +20,43 @@
|
||||
"test:e2e": "echo 'No e2e tests implemented yet.'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/apollo": "10.0.0",
|
||||
"@nestjs/common": "8.2.3",
|
||||
"@nestjs/core": "8.2.3",
|
||||
"@nestjs/graphql": "10.0.0",
|
||||
"@nestjs/platform-express": "8.2.3",
|
||||
"@nestjs/apollo": "^10.0.17",
|
||||
"@nestjs/common": "9.0.1",
|
||||
"@nestjs/core": "9.0.1",
|
||||
"@nestjs/graphql": "10.0.18",
|
||||
"@nestjs/platform-express": "9.0.1",
|
||||
"@prisma/client": "3.8.1",
|
||||
"apollo-server": "3.6.2",
|
||||
"apollo-server-express": "3.6.2",
|
||||
"graphql": "15.7.2",
|
||||
"graphql-tools": "7.0.5",
|
||||
"prisma-binding": "2.3.16",
|
||||
"class-transformer": "0.5.1",
|
||||
"class-validator": "0.13.2",
|
||||
"graphql": "15.8.0",
|
||||
"graphql-subscriptions": "2.0.0",
|
||||
"reflect-metadata": "0.1.13",
|
||||
"rimraf": "3.0.2",
|
||||
"rxjs": "7.4.0"
|
||||
"rxjs": "7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "8.1.5",
|
||||
"@nestjs/schematics": "8.0.8",
|
||||
"@nestjs/testing": "8.2.3",
|
||||
"@nestjs/cli": "9.0.0",
|
||||
"@nestjs/schematics": "9.0.1",
|
||||
"@nestjs/testing": "9.0.1",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/node": "16.11.26",
|
||||
"@types/supertest": "2.0.11",
|
||||
"jest": "27.5.1",
|
||||
"prettier": "2.5.1",
|
||||
"supertest": "6.1.6",
|
||||
"ts-jest": "27.0.7",
|
||||
"ts-loader": "9.2.8",
|
||||
"ts-node": "10.4.0",
|
||||
"tsconfig-paths": "3.11.0",
|
||||
"@typescript-eslint/eslint-plugin": "4.33.0",
|
||||
"@typescript-eslint/parser": "4.33.0",
|
||||
"eslint": "7.32.0",
|
||||
"eslint-config-prettier": "8.3.0",
|
||||
"eslint-plugin-import": "2.25.4",
|
||||
"typescript": "4.3.5"
|
||||
"@types/node": "18.0.3",
|
||||
"@types/supertest": "2.0.12",
|
||||
"@typescript-eslint/eslint-plugin": "5.30.5",
|
||||
"@typescript-eslint/parser": "5.30.5",
|
||||
"eslint": "8.19.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-import": "2.26.0",
|
||||
"jest": "28.1.2",
|
||||
"prettier": "2.7.1",
|
||||
"prisma": "^4.0.0",
|
||||
"supertest": "6.2.4",
|
||||
"ts-jest": "28.0.5",
|
||||
"ts-loader": "9.3.1",
|
||||
"ts-morph": "15.1.0",
|
||||
"ts-node": "10.8.2",
|
||||
"tsconfig-paths": "4.0.0",
|
||||
"typescript": "4.7.4"
|
||||
}
|
||||
}
|
||||
|
||||
18
sample/22-graphql-prisma/prisma/schema.prisma
Executable file
18
sample/22-graphql-prisma/prisma/schema.prisma
Executable file
@@ -0,0 +1,18 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = "file:./dev.db"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
model Post {
|
||||
id String @id @default(uuid())
|
||||
title String
|
||||
text String
|
||||
isPublished Boolean @default(false)
|
||||
}
|
||||
14
sample/22-graphql-prisma/src/app.module.ts
Normal file → Executable file
14
sample/22-graphql-prisma/src/app.module.ts
Normal file → Executable file
@@ -1,18 +1,16 @@
|
||||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
import { GraphQLOptionsHost } from './graphql.options';
|
||||
import { PostsModule } from './posts/posts.module';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
GraphQLModule.forRootAsync<ApolloDriverConfig>({
|
||||
driver: ApolloDriver,
|
||||
useClass: GraphQLOptionsHost,
|
||||
}),
|
||||
PrismaModule,
|
||||
PostsModule,
|
||||
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||
driver: ApolloDriver,
|
||||
typePaths: ['./**/*.graphql'],
|
||||
installSubscriptionHandlers: true,
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { ApolloDriverConfig } from '@nestjs/apollo';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { GqlOptionsFactory } from '@nestjs/graphql';
|
||||
import { join } from 'path';
|
||||
|
||||
@Injectable()
|
||||
export class GraphQLOptionsHost implements GqlOptionsFactory {
|
||||
createGqlOptions(): Promise<ApolloDriverConfig> | ApolloDriverConfig {
|
||||
return {
|
||||
typePaths: ['./src/**/*.graphql'],
|
||||
path: '/',
|
||||
installSubscriptionHandlers: true,
|
||||
resolverValidationOptions: {
|
||||
requireResolversForResolveType: 'ignore',
|
||||
},
|
||||
definitions: {
|
||||
path: join(process.cwd(), 'src/graphql.schema.d.ts'),
|
||||
outputAs: 'class',
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
183
sample/22-graphql-prisma/src/graphql.schema.d.ts
vendored
183
sample/22-graphql-prisma/src/graphql.schema.d.ts
vendored
@@ -1,183 +0,0 @@
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------
|
||||
* THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
|
||||
* -------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export enum MutationType {
|
||||
CREATED = "CREATED",
|
||||
UPDATED = "UPDATED",
|
||||
DELETED = "DELETED"
|
||||
}
|
||||
|
||||
export enum PostOrderByInput {
|
||||
id_ASC = "id_ASC",
|
||||
id_DESC = "id_DESC",
|
||||
isPublished_ASC = "isPublished_ASC",
|
||||
isPublished_DESC = "isPublished_DESC",
|
||||
title_ASC = "title_ASC",
|
||||
title_DESC = "title_DESC",
|
||||
text_ASC = "text_ASC",
|
||||
text_DESC = "text_DESC"
|
||||
}
|
||||
|
||||
export class PostCreateInput {
|
||||
id?: Nullable<string>;
|
||||
isPublished?: Nullable<boolean>;
|
||||
title: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class PostSubscriptionWhereInput {
|
||||
AND?: Nullable<PostSubscriptionWhereInput[]>;
|
||||
OR?: Nullable<PostSubscriptionWhereInput[]>;
|
||||
NOT?: Nullable<PostSubscriptionWhereInput[]>;
|
||||
mutation_in?: Nullable<MutationType[]>;
|
||||
updatedFields_contains?: Nullable<string>;
|
||||
updatedFields_contains_every?: Nullable<string[]>;
|
||||
updatedFields_contains_some?: Nullable<string[]>;
|
||||
node?: Nullable<PostWhereInput>;
|
||||
}
|
||||
|
||||
export class PostUpdateInput {
|
||||
isPublished?: Nullable<boolean>;
|
||||
title?: Nullable<string>;
|
||||
text?: Nullable<string>;
|
||||
}
|
||||
|
||||
export class PostUpdateManyMutationInput {
|
||||
isPublished?: Nullable<boolean>;
|
||||
title?: Nullable<string>;
|
||||
text?: Nullable<string>;
|
||||
}
|
||||
|
||||
export class PostWhereInput {
|
||||
AND?: Nullable<PostWhereInput[]>;
|
||||
OR?: Nullable<PostWhereInput[]>;
|
||||
NOT?: Nullable<PostWhereInput[]>;
|
||||
id?: Nullable<string>;
|
||||
id_not?: Nullable<string>;
|
||||
id_in?: Nullable<string[]>;
|
||||
id_not_in?: Nullable<string[]>;
|
||||
id_lt?: Nullable<string>;
|
||||
id_lte?: Nullable<string>;
|
||||
id_gt?: Nullable<string>;
|
||||
id_gte?: Nullable<string>;
|
||||
id_contains?: Nullable<string>;
|
||||
id_not_contains?: Nullable<string>;
|
||||
id_starts_with?: Nullable<string>;
|
||||
id_not_starts_with?: Nullable<string>;
|
||||
id_ends_with?: Nullable<string>;
|
||||
id_not_ends_with?: Nullable<string>;
|
||||
isPublished?: Nullable<boolean>;
|
||||
isPublished_not?: Nullable<boolean>;
|
||||
title?: Nullable<string>;
|
||||
title_not?: Nullable<string>;
|
||||
title_in?: Nullable<string[]>;
|
||||
title_not_in?: Nullable<string[]>;
|
||||
title_lt?: Nullable<string>;
|
||||
title_lte?: Nullable<string>;
|
||||
title_gt?: Nullable<string>;
|
||||
title_gte?: Nullable<string>;
|
||||
title_contains?: Nullable<string>;
|
||||
title_not_contains?: Nullable<string>;
|
||||
title_starts_with?: Nullable<string>;
|
||||
title_not_starts_with?: Nullable<string>;
|
||||
title_ends_with?: Nullable<string>;
|
||||
title_not_ends_with?: Nullable<string>;
|
||||
text?: Nullable<string>;
|
||||
text_not?: Nullable<string>;
|
||||
text_in?: Nullable<string[]>;
|
||||
text_not_in?: Nullable<string[]>;
|
||||
text_lt?: Nullable<string>;
|
||||
text_lte?: Nullable<string>;
|
||||
text_gt?: Nullable<string>;
|
||||
text_gte?: Nullable<string>;
|
||||
text_contains?: Nullable<string>;
|
||||
text_not_contains?: Nullable<string>;
|
||||
text_starts_with?: Nullable<string>;
|
||||
text_not_starts_with?: Nullable<string>;
|
||||
text_ends_with?: Nullable<string>;
|
||||
text_not_ends_with?: Nullable<string>;
|
||||
}
|
||||
|
||||
export class PostWhereUniqueInput {
|
||||
id?: Nullable<string>;
|
||||
}
|
||||
|
||||
export interface Node {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class AggregatePost {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export class BatchPayload {
|
||||
count: Long;
|
||||
}
|
||||
|
||||
export abstract class IMutation {
|
||||
abstract createPost(data: PostCreateInput): Post | Promise<Post>;
|
||||
abstract updatePost(data: PostUpdateInput, where: PostWhereUniqueInput): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
abstract deletePost(where: PostWhereUniqueInput): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
abstract upsertPost(where: PostWhereUniqueInput, create: PostCreateInput, update: PostUpdateInput): Post | Promise<Post>;
|
||||
abstract updateManyPosts(data: PostUpdateManyMutationInput, where?: Nullable<PostWhereInput>): BatchPayload | Promise<BatchPayload>;
|
||||
abstract deleteManyPosts(where?: Nullable<PostWhereInput>): BatchPayload | Promise<BatchPayload>;
|
||||
}
|
||||
|
||||
export class PageInfo {
|
||||
hasNextPage: boolean;
|
||||
hasPreviousPage: boolean;
|
||||
startCursor?: Nullable<string>;
|
||||
endCursor?: Nullable<string>;
|
||||
}
|
||||
|
||||
export class Post implements Node {
|
||||
id: string;
|
||||
isPublished: boolean;
|
||||
title: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class PostConnection {
|
||||
pageInfo: PageInfo;
|
||||
edges: Nullable<PostEdge>[];
|
||||
aggregate: AggregatePost;
|
||||
}
|
||||
|
||||
export class PostEdge {
|
||||
node: Post;
|
||||
cursor: string;
|
||||
}
|
||||
|
||||
export class PostPreviousValues {
|
||||
id: string;
|
||||
isPublished: boolean;
|
||||
title: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class PostSubscriptionPayload {
|
||||
mutation: MutationType;
|
||||
node?: Nullable<Post>;
|
||||
updatedFields?: Nullable<string[]>;
|
||||
previousValues?: Nullable<PostPreviousValues>;
|
||||
}
|
||||
|
||||
export abstract class IQuery {
|
||||
abstract posts(where?: Nullable<PostWhereInput>, orderBy?: Nullable<PostOrderByInput>, skip?: Nullable<number>, after?: Nullable<string>, before?: Nullable<string>, first?: Nullable<number>, last?: Nullable<number>): Nullable<Post>[] | Promise<Nullable<Post>[]>;
|
||||
abstract post(where: PostWhereUniqueInput): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
abstract postsConnection(where?: Nullable<PostWhereInput>, orderBy?: Nullable<PostOrderByInput>, skip?: Nullable<number>, after?: Nullable<string>, before?: Nullable<string>, first?: Nullable<number>, last?: Nullable<number>): PostConnection | Promise<PostConnection>;
|
||||
abstract node(id: string): Nullable<Node> | Promise<Nullable<Node>>;
|
||||
}
|
||||
|
||||
export abstract class ISubscription {
|
||||
abstract post(where?: Nullable<PostSubscriptionWhereInput>): Nullable<PostSubscriptionPayload> | Promise<Nullable<PostSubscriptionPayload>>;
|
||||
}
|
||||
|
||||
export type Long = any;
|
||||
type Nullable<T> = T | null;
|
||||
48
sample/22-graphql-prisma/src/graphql.schema.ts
Executable file
48
sample/22-graphql-prisma/src/graphql.schema.ts
Executable file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* -------------------------------------------------------
|
||||
* THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
|
||||
* -------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export class NewPost {
|
||||
title: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class UpdatePost {
|
||||
id: string;
|
||||
title?: Nullable<string>;
|
||||
text?: Nullable<string>;
|
||||
isPublished?: Nullable<boolean>;
|
||||
}
|
||||
|
||||
export class Post {
|
||||
id: string;
|
||||
title: string;
|
||||
text: string;
|
||||
isPublished: boolean;
|
||||
}
|
||||
|
||||
export abstract class IQuery {
|
||||
abstract posts(): Post[] | Promise<Post[]>;
|
||||
|
||||
abstract post(id: string): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
}
|
||||
|
||||
export abstract class IMutation {
|
||||
abstract createPost(input: NewPost): Post | Promise<Post>;
|
||||
|
||||
abstract updatePost(
|
||||
input: UpdatePost,
|
||||
): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
|
||||
abstract deletePost(id: string): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
}
|
||||
|
||||
export abstract class ISubscription {
|
||||
abstract postCreated(): Nullable<Post> | Promise<Nullable<Post>>;
|
||||
}
|
||||
|
||||
type Nullable<T> = T | null;
|
||||
4
sample/22-graphql-prisma/src/main.ts
Normal file → Executable file
4
sample/22-graphql-prisma/src/main.ts
Normal file → Executable file
@@ -1,9 +1,13 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
|
||||
await app.listen(3000);
|
||||
console.log(`Application is running on: ${await app.getUrl()}`);
|
||||
console.log(`GraphQL Playground: ${await app.getUrl()}/graphql`);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
7
sample/22-graphql-prisma/src/posts/posts.module.ts
Normal file → Executable file
7
sample/22-graphql-prisma/src/posts/posts.module.ts
Normal file → Executable file
@@ -1,9 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrismaModule } from './../prisma/prisma.module';
|
||||
import { PostsResolver } from './posts.resolver';
|
||||
import { PostsResolvers } from './posts.resolvers';
|
||||
import { PostsService } from './posts.service';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
|
||||
@Module({
|
||||
providers: [PostsResolver],
|
||||
providers: [PostsResolvers, PostsService],
|
||||
imports: [PrismaModule],
|
||||
})
|
||||
export class PostsModule {}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import {
|
||||
Args,
|
||||
Info,
|
||||
Mutation,
|
||||
Query,
|
||||
Resolver,
|
||||
Subscription,
|
||||
} from '@nestjs/graphql';
|
||||
import { Post } from '../graphql.schema';
|
||||
import { BatchPayload } from '../prisma/prisma.binding';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Resolver()
|
||||
export class PostsResolver {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Query('posts')
|
||||
async getPosts(@Args() args, @Info() info): Promise<Post[]> {
|
||||
return this.prisma.query.posts(args, info);
|
||||
}
|
||||
|
||||
@Query('post')
|
||||
async getPost(@Args() args, @Info() info): Promise<Post> {
|
||||
return this.prisma.query.post(args, info);
|
||||
}
|
||||
|
||||
@Mutation('createPost')
|
||||
async createPost(@Args() args, @Info() info): Promise<Post> {
|
||||
return this.prisma.mutation.createPost(args, info);
|
||||
}
|
||||
|
||||
@Mutation('updatePost')
|
||||
async updatePost(@Args() args, @Info() info): Promise<Post> {
|
||||
return this.prisma.mutation.updatePost(args, info);
|
||||
}
|
||||
|
||||
@Mutation('updateManyPosts')
|
||||
async updateManyPosts(@Args() args, @Info() info): Promise<BatchPayload> {
|
||||
return this.prisma.mutation.updateManyPosts(args, info);
|
||||
}
|
||||
|
||||
@Mutation('deletePost')
|
||||
async deletePost(@Args() args, @Info() info): Promise<Post> {
|
||||
return this.prisma.mutation.deletePost(args, info);
|
||||
}
|
||||
|
||||
@Mutation('deleteManyPosts')
|
||||
async deleteManyPosts(@Args() args, @Info() info): Promise<BatchPayload> {
|
||||
return this.prisma.mutation.deleteManyPosts(args, info);
|
||||
}
|
||||
|
||||
@Subscription('post')
|
||||
onPostMutation(@Args() args, @Info() info) {
|
||||
return this.prisma.subscription.post(args, info);
|
||||
}
|
||||
}
|
||||
43
sample/22-graphql-prisma/src/posts/posts.resolvers.ts
Executable file
43
sample/22-graphql-prisma/src/posts/posts.resolvers.ts
Executable file
@@ -0,0 +1,43 @@
|
||||
import { Resolver, Query, Mutation, Args, Subscription } from '@nestjs/graphql';
|
||||
import { PostsService } from './posts.service';
|
||||
import { Post, NewPost, UpdatePost } from 'src/graphql.schema';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
|
||||
const pubSub = new PubSub();
|
||||
|
||||
@Resolver('Post')
|
||||
export class PostsResolvers {
|
||||
constructor(private readonly postService: PostsService) {}
|
||||
|
||||
@Query('posts')
|
||||
async posts(): Promise<Post[]> {
|
||||
return this.postService.findAll();
|
||||
}
|
||||
|
||||
@Query('post')
|
||||
async post(@Args('id') args: string): Promise<Post> {
|
||||
return this.postService.findOne(args);
|
||||
}
|
||||
|
||||
@Mutation('createPost')
|
||||
async create(@Args('input') args: NewPost): Promise<Post> {
|
||||
const createdPost = await this.postService.create(args);
|
||||
pubSub.publish('postCreated', { postCreated: createdPost });
|
||||
return createdPost;
|
||||
}
|
||||
|
||||
@Mutation('updatePost')
|
||||
async update(@Args('input') args: UpdatePost): Promise<Post> {
|
||||
return this.postService.update(args);
|
||||
}
|
||||
|
||||
@Mutation('deletePost')
|
||||
async delete(@Args('id') args: string): Promise<Post> {
|
||||
return this.postService.delete(args);
|
||||
}
|
||||
|
||||
@Subscription('postCreated')
|
||||
postCreated() {
|
||||
return pubSub.asyncIterator('postCreated');
|
||||
}
|
||||
}
|
||||
48
sample/22-graphql-prisma/src/posts/posts.service.ts
Executable file
48
sample/22-graphql-prisma/src/posts/posts.service.ts
Executable file
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Post } from '@prisma/client';
|
||||
import { NewPost, UpdatePost } from 'src/graphql.schema';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class PostsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findOne(id: string): Promise<Post | null> {
|
||||
return this.prisma.post.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(): Promise<Post[]> {
|
||||
return this.prisma.post.findMany({});
|
||||
}
|
||||
|
||||
async create(input: NewPost): Promise<Post> {
|
||||
return this.prisma.post.create({
|
||||
data: input,
|
||||
});
|
||||
}
|
||||
|
||||
async update(params: UpdatePost): Promise<Post> {
|
||||
const { id, ...params_without_id } = params;
|
||||
|
||||
return this.prisma.post.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data: {
|
||||
...params_without_id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<Post> {
|
||||
return this.prisma.post.delete({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
33
sample/22-graphql-prisma/src/posts/schema.graphql
Executable file
33
sample/22-graphql-prisma/src/posts/schema.graphql
Executable file
@@ -0,0 +1,33 @@
|
||||
type Post {
|
||||
id: ID!
|
||||
title: String!
|
||||
text: String!
|
||||
isPublished: Boolean!
|
||||
}
|
||||
|
||||
input NewPost {
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
input UpdatePost {
|
||||
id: ID!
|
||||
title: String
|
||||
text: String
|
||||
isPublished: Boolean
|
||||
}
|
||||
|
||||
type Query {
|
||||
posts: [Post!]!
|
||||
post(id: ID!): Post
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createPost(input: NewPost!): Post!
|
||||
updatePost(input: UpdatePost!): Post
|
||||
deletePost(id: ID!): Post
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
postCreated: Post
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
# source: https://eu1.prisma.sh/adam-gajzlerowicz-1dadb3/demo/dev
|
||||
# timestamp: Sun Jan 26 2020 09:49:46 GMT+0100 (Central European Standard Time)
|
||||
|
||||
type AggregatePost {
|
||||
count: Int!
|
||||
}
|
||||
|
||||
type BatchPayload {
|
||||
"""The number of nodes that have been affected by the Batch operation."""
|
||||
count: Long!
|
||||
}
|
||||
|
||||
"""
|
||||
The `Long` scalar type represents non-fractional signed whole numeric values.
|
||||
Long can represent values between -(2^63) and 2^63 - 1.
|
||||
"""
|
||||
scalar Long
|
||||
|
||||
type Mutation {
|
||||
createPost(data: PostCreateInput!): Post!
|
||||
updatePost(data: PostUpdateInput!, where: PostWhereUniqueInput!): Post
|
||||
deletePost(where: PostWhereUniqueInput!): Post
|
||||
upsertPost(where: PostWhereUniqueInput!, create: PostCreateInput!, update: PostUpdateInput!): Post!
|
||||
updateManyPosts(data: PostUpdateManyMutationInput!, where: PostWhereInput): BatchPayload!
|
||||
deleteManyPosts(where: PostWhereInput): BatchPayload!
|
||||
}
|
||||
|
||||
enum MutationType {
|
||||
CREATED
|
||||
UPDATED
|
||||
DELETED
|
||||
}
|
||||
|
||||
"""An object with an ID"""
|
||||
interface Node {
|
||||
"""The id of the object."""
|
||||
id: ID!
|
||||
}
|
||||
|
||||
"""Information about pagination in a connection."""
|
||||
type PageInfo {
|
||||
"""When paginating forwards, are there more items?"""
|
||||
hasNextPage: Boolean!
|
||||
|
||||
"""When paginating backwards, are there more items?"""
|
||||
hasPreviousPage: Boolean!
|
||||
|
||||
"""When paginating backwards, the cursor to continue."""
|
||||
startCursor: String
|
||||
|
||||
"""When paginating forwards, the cursor to continue."""
|
||||
endCursor: String
|
||||
}
|
||||
|
||||
type Post implements Node {
|
||||
id: ID!
|
||||
isPublished: Boolean!
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
"""A connection to a list of items."""
|
||||
type PostConnection {
|
||||
"""Information to aid in pagination."""
|
||||
pageInfo: PageInfo!
|
||||
|
||||
"""A list of edges."""
|
||||
edges: [PostEdge]!
|
||||
aggregate: AggregatePost!
|
||||
}
|
||||
|
||||
input PostCreateInput {
|
||||
id: ID
|
||||
isPublished: Boolean
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
"""An edge in a connection."""
|
||||
type PostEdge {
|
||||
"""The item at the end of the edge."""
|
||||
node: Post!
|
||||
|
||||
"""A cursor for use in pagination."""
|
||||
cursor: String!
|
||||
}
|
||||
|
||||
enum PostOrderByInput {
|
||||
id_ASC
|
||||
id_DESC
|
||||
isPublished_ASC
|
||||
isPublished_DESC
|
||||
title_ASC
|
||||
title_DESC
|
||||
text_ASC
|
||||
text_DESC
|
||||
}
|
||||
|
||||
type PostPreviousValues {
|
||||
id: ID!
|
||||
isPublished: Boolean!
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
type PostSubscriptionPayload {
|
||||
mutation: MutationType!
|
||||
node: Post
|
||||
updatedFields: [String!]
|
||||
previousValues: PostPreviousValues
|
||||
}
|
||||
|
||||
input PostSubscriptionWhereInput {
|
||||
"""Logical AND on all given filters."""
|
||||
AND: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""Logical OR on all given filters."""
|
||||
OR: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""Logical NOT on all given filters combined by AND."""
|
||||
NOT: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""The subscription event gets dispatched when it's listed in mutation_in"""
|
||||
mutation_in: [MutationType!]
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when one of the updated fields names is included in this list
|
||||
"""
|
||||
updatedFields_contains: String
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when all of the field names included in this list have been updated
|
||||
"""
|
||||
updatedFields_contains_every: [String!]
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when some of the field names included in this list have been updated
|
||||
"""
|
||||
updatedFields_contains_some: [String!]
|
||||
node: PostWhereInput
|
||||
}
|
||||
|
||||
input PostUpdateInput {
|
||||
isPublished: Boolean
|
||||
title: String
|
||||
text: String
|
||||
}
|
||||
|
||||
input PostUpdateManyMutationInput {
|
||||
isPublished: Boolean
|
||||
title: String
|
||||
text: String
|
||||
}
|
||||
|
||||
input PostWhereInput {
|
||||
"""Logical AND on all given filters."""
|
||||
AND: [PostWhereInput!]
|
||||
|
||||
"""Logical OR on all given filters."""
|
||||
OR: [PostWhereInput!]
|
||||
|
||||
"""Logical NOT on all given filters combined by AND."""
|
||||
NOT: [PostWhereInput!]
|
||||
id: ID
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
id_not: ID
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
id_in: [ID!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
id_not_in: [ID!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
id_lt: ID
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
id_lte: ID
|
||||
|
||||
"""All values greater than the given value."""
|
||||
id_gt: ID
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
id_gte: ID
|
||||
|
||||
"""All values containing the given string."""
|
||||
id_contains: ID
|
||||
|
||||
"""All values not containing the given string."""
|
||||
id_not_contains: ID
|
||||
|
||||
"""All values starting with the given string."""
|
||||
id_starts_with: ID
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
id_not_starts_with: ID
|
||||
|
||||
"""All values ending with the given string."""
|
||||
id_ends_with: ID
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
id_not_ends_with: ID
|
||||
isPublished: Boolean
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
isPublished_not: Boolean
|
||||
title: String
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
title_not: String
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
title_in: [String!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
title_not_in: [String!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
title_lt: String
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
title_lte: String
|
||||
|
||||
"""All values greater than the given value."""
|
||||
title_gt: String
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
title_gte: String
|
||||
|
||||
"""All values containing the given string."""
|
||||
title_contains: String
|
||||
|
||||
"""All values not containing the given string."""
|
||||
title_not_contains: String
|
||||
|
||||
"""All values starting with the given string."""
|
||||
title_starts_with: String
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
title_not_starts_with: String
|
||||
|
||||
"""All values ending with the given string."""
|
||||
title_ends_with: String
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
title_not_ends_with: String
|
||||
text: String
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
text_not: String
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
text_in: [String!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
text_not_in: [String!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
text_lt: String
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
text_lte: String
|
||||
|
||||
"""All values greater than the given value."""
|
||||
text_gt: String
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
text_gte: String
|
||||
|
||||
"""All values containing the given string."""
|
||||
text_contains: String
|
||||
|
||||
"""All values not containing the given string."""
|
||||
text_not_contains: String
|
||||
|
||||
"""All values starting with the given string."""
|
||||
text_starts_with: String
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
text_not_starts_with: String
|
||||
|
||||
"""All values ending with the given string."""
|
||||
text_ends_with: String
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
text_not_ends_with: String
|
||||
}
|
||||
|
||||
input PostWhereUniqueInput {
|
||||
id: ID
|
||||
}
|
||||
|
||||
type Query {
|
||||
posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post]!
|
||||
post(where: PostWhereUniqueInput!): Post
|
||||
postsConnection(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): PostConnection!
|
||||
|
||||
"""Fetches an object given its ID"""
|
||||
node(
|
||||
"""The ID of an object"""
|
||||
id: ID!
|
||||
): Node
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
post(where: PostSubscriptionWhereInput): PostSubscriptionPayload
|
||||
}
|
||||
@@ -1,629 +0,0 @@
|
||||
import { GraphQLResolveInfo, GraphQLSchema } from 'graphql';
|
||||
import { Options } from 'graphql-binding';
|
||||
import { IResolvers } from 'graphql-tools';
|
||||
import { BasePrismaOptions, makePrismaBindingClass } from 'prisma-binding';
|
||||
|
||||
export interface Query {
|
||||
posts: <T = Post[]>(
|
||||
args: {
|
||||
where?: PostWhereInput;
|
||||
orderBy?: PostOrderByInput;
|
||||
skip?: Int;
|
||||
after?: String;
|
||||
before?: String;
|
||||
first?: Int;
|
||||
last?: Int;
|
||||
},
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
post: <T = Post | null>(
|
||||
args: { where: PostWhereUniqueInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
postsConnection: <T = PostConnection>(
|
||||
args: {
|
||||
where?: PostWhereInput;
|
||||
orderBy?: PostOrderByInput;
|
||||
skip?: Int;
|
||||
after?: String;
|
||||
before?: String;
|
||||
first?: Int;
|
||||
last?: Int;
|
||||
},
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
node: <T = Node | null>(
|
||||
args: { id: ID_Output },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
}
|
||||
|
||||
export interface Mutation {
|
||||
createPost: <T = Post>(
|
||||
args: { data: PostCreateInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
updatePost: <T = Post | null>(
|
||||
args: { data: PostUpdateInput; where: PostWhereUniqueInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
deletePost: <T = Post | null>(
|
||||
args: { where: PostWhereUniqueInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
upsertPost: <T = Post>(
|
||||
args: {
|
||||
where: PostWhereUniqueInput;
|
||||
create: PostCreateInput;
|
||||
update: PostUpdateInput;
|
||||
},
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
updateManyPosts: <T = BatchPayload>(
|
||||
args: { data: PostUpdateInput; where?: PostWhereInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
deleteManyPosts: <T = BatchPayload>(
|
||||
args: { where?: PostWhereInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<T>;
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
post: <T = PostSubscriptionPayload | null>(
|
||||
args: { where?: PostSubscriptionWhereInput },
|
||||
info?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
) => Promise<AsyncIterator<T>>;
|
||||
}
|
||||
|
||||
export interface Exists {
|
||||
Post: (where?: PostWhereInput) => Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface Prisma {
|
||||
query: Query;
|
||||
mutation: Mutation;
|
||||
subscription: Subscription;
|
||||
exists: Exists;
|
||||
request: <T = any>(
|
||||
query: string,
|
||||
variables?: { [key: string]: any },
|
||||
) => Promise<T>;
|
||||
delegate(
|
||||
operation: 'query' | 'mutation',
|
||||
fieldName: string,
|
||||
args: {
|
||||
[key: string]: any;
|
||||
},
|
||||
infoOrQuery?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
): Promise<any>;
|
||||
delegateSubscription(
|
||||
fieldName: string,
|
||||
args?: {
|
||||
[key: string]: any;
|
||||
},
|
||||
infoOrQuery?: GraphQLResolveInfo | string,
|
||||
options?: Options,
|
||||
): Promise<AsyncIterator<any>>;
|
||||
getAbstractResolvers(filterSchema?: GraphQLSchema | string): IResolvers;
|
||||
}
|
||||
|
||||
export interface BindingConstructor<T> {
|
||||
new (options: BasePrismaOptions): T;
|
||||
}
|
||||
/**
|
||||
* Type Defs
|
||||
*/
|
||||
|
||||
const typeDefs = `type AggregatePost {
|
||||
count: Int!
|
||||
}
|
||||
|
||||
type BatchPayload {
|
||||
"""The number of nodes that have been affected by the Batch operation."""
|
||||
count: Long!
|
||||
}
|
||||
|
||||
"""
|
||||
The \`Long\` scalar type represents non-fractional signed whole numeric values.
|
||||
Long can represent values between -(2^63) and 2^63 - 1.
|
||||
"""
|
||||
scalar Long
|
||||
|
||||
type Mutation {
|
||||
createPost(data: PostCreateInput!): Post!
|
||||
updatePost(data: PostUpdateInput!, where: PostWhereUniqueInput!): Post
|
||||
deletePost(where: PostWhereUniqueInput!): Post
|
||||
upsertPost(where: PostWhereUniqueInput!, create: PostCreateInput!, update: PostUpdateInput!): Post!
|
||||
updateManyPosts(data: PostUpdateInput!, where: PostWhereInput): BatchPayload!
|
||||
deleteManyPosts(where: PostWhereInput): BatchPayload!
|
||||
}
|
||||
|
||||
enum MutationType {
|
||||
CREATED
|
||||
UPDATED
|
||||
DELETED
|
||||
}
|
||||
|
||||
"""An object with an ID"""
|
||||
interface Node {
|
||||
"""The id of the object."""
|
||||
id: ID!
|
||||
}
|
||||
|
||||
"""Information about pagination in a connection."""
|
||||
type PageInfo {
|
||||
"""When paginating forwards, are there more items?"""
|
||||
hasNextPage: Boolean!
|
||||
|
||||
"""When paginating backwards, are there more items?"""
|
||||
hasPreviousPage: Boolean!
|
||||
|
||||
"""When paginating backwards, the cursor to continue."""
|
||||
startCursor: String
|
||||
|
||||
"""When paginating forwards, the cursor to continue."""
|
||||
endCursor: String
|
||||
}
|
||||
|
||||
type Post implements Node {
|
||||
id: ID!
|
||||
isPublished: Boolean!
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
"""A connection to a list of items."""
|
||||
type PostConnection {
|
||||
"""Information to aid in pagination."""
|
||||
pageInfo: PageInfo!
|
||||
|
||||
"""A list of edges."""
|
||||
edges: [PostEdge]!
|
||||
aggregate: AggregatePost!
|
||||
}
|
||||
|
||||
input PostCreateInput {
|
||||
isPublished: Boolean
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
"""An edge in a connection."""
|
||||
type PostEdge {
|
||||
"""The item at the end of the edge."""
|
||||
node: Post!
|
||||
|
||||
"""A cursor for use in pagination."""
|
||||
cursor: String!
|
||||
}
|
||||
|
||||
enum PostOrderByInput {
|
||||
id_ASC
|
||||
id_DESC
|
||||
isPublished_ASC
|
||||
isPublished_DESC
|
||||
title_ASC
|
||||
title_DESC
|
||||
text_ASC
|
||||
text_DESC
|
||||
updatedAt_ASC
|
||||
updatedAt_DESC
|
||||
createdAt_ASC
|
||||
createdAt_DESC
|
||||
}
|
||||
|
||||
type PostPreviousValues {
|
||||
id: ID!
|
||||
isPublished: Boolean!
|
||||
title: String!
|
||||
text: String!
|
||||
}
|
||||
|
||||
type PostSubscriptionPayload {
|
||||
mutation: MutationType!
|
||||
node: Post
|
||||
updatedFields: [String!]
|
||||
previousValues: PostPreviousValues
|
||||
}
|
||||
|
||||
input PostSubscriptionWhereInput {
|
||||
"""Logical AND on all given filters."""
|
||||
AND: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""Logical OR on all given filters."""
|
||||
OR: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""Logical NOT on all given filters combined by AND."""
|
||||
NOT: [PostSubscriptionWhereInput!]
|
||||
|
||||
"""
|
||||
The subscription event gets dispatched when it's listed in mutation_in
|
||||
"""
|
||||
mutation_in: [MutationType!]
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when one of the updated fields names is included in this list
|
||||
"""
|
||||
updatedFields_contains: String
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when all of the field names included in this list have been updated
|
||||
"""
|
||||
updatedFields_contains_every: [String!]
|
||||
|
||||
"""
|
||||
The subscription event gets only dispatched when some of the field names included in this list have been updated
|
||||
"""
|
||||
updatedFields_contains_some: [String!]
|
||||
node: PostWhereInput
|
||||
}
|
||||
|
||||
input PostUpdateInput {
|
||||
isPublished: Boolean
|
||||
title: String
|
||||
text: String
|
||||
}
|
||||
|
||||
input PostWhereInput {
|
||||
"""Logical AND on all given filters."""
|
||||
AND: [PostWhereInput!]
|
||||
|
||||
"""Logical OR on all given filters."""
|
||||
OR: [PostWhereInput!]
|
||||
|
||||
"""Logical NOT on all given filters combined by AND."""
|
||||
NOT: [PostWhereInput!]
|
||||
id: ID
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
id_not: ID
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
id_in: [ID!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
id_not_in: [ID!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
id_lt: ID
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
id_lte: ID
|
||||
|
||||
"""All values greater than the given value."""
|
||||
id_gt: ID
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
id_gte: ID
|
||||
|
||||
"""All values containing the given string."""
|
||||
id_contains: ID
|
||||
|
||||
"""All values not containing the given string."""
|
||||
id_not_contains: ID
|
||||
|
||||
"""All values starting with the given string."""
|
||||
id_starts_with: ID
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
id_not_starts_with: ID
|
||||
|
||||
"""All values ending with the given string."""
|
||||
id_ends_with: ID
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
id_not_ends_with: ID
|
||||
isPublished: Boolean
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
isPublished_not: Boolean
|
||||
title: String
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
title_not: String
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
title_in: [String!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
title_not_in: [String!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
title_lt: String
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
title_lte: String
|
||||
|
||||
"""All values greater than the given value."""
|
||||
title_gt: String
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
title_gte: String
|
||||
|
||||
"""All values containing the given string."""
|
||||
title_contains: String
|
||||
|
||||
"""All values not containing the given string."""
|
||||
title_not_contains: String
|
||||
|
||||
"""All values starting with the given string."""
|
||||
title_starts_with: String
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
title_not_starts_with: String
|
||||
|
||||
"""All values ending with the given string."""
|
||||
title_ends_with: String
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
title_not_ends_with: String
|
||||
text: String
|
||||
|
||||
"""All values that are not equal to given value."""
|
||||
text_not: String
|
||||
|
||||
"""All values that are contained in given list."""
|
||||
text_in: [String!]
|
||||
|
||||
"""All values that are not contained in given list."""
|
||||
text_not_in: [String!]
|
||||
|
||||
"""All values less than the given value."""
|
||||
text_lt: String
|
||||
|
||||
"""All values less than or equal the given value."""
|
||||
text_lte: String
|
||||
|
||||
"""All values greater than the given value."""
|
||||
text_gt: String
|
||||
|
||||
"""All values greater than or equal the given value."""
|
||||
text_gte: String
|
||||
|
||||
"""All values containing the given string."""
|
||||
text_contains: String
|
||||
|
||||
"""All values not containing the given string."""
|
||||
text_not_contains: String
|
||||
|
||||
"""All values starting with the given string."""
|
||||
text_starts_with: String
|
||||
|
||||
"""All values not starting with the given string."""
|
||||
text_not_starts_with: String
|
||||
|
||||
"""All values ending with the given string."""
|
||||
text_ends_with: String
|
||||
|
||||
"""All values not ending with the given string."""
|
||||
text_not_ends_with: String
|
||||
}
|
||||
|
||||
input PostWhereUniqueInput {
|
||||
id: ID
|
||||
}
|
||||
|
||||
type Query {
|
||||
posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post]!
|
||||
post(where: PostWhereUniqueInput!): Post
|
||||
postsConnection(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): PostConnection!
|
||||
|
||||
"""Fetches an object given its ID"""
|
||||
node(
|
||||
"""The ID of an object"""
|
||||
id: ID!
|
||||
): Node
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
post(where: PostSubscriptionWhereInput): PostSubscriptionPayload
|
||||
}
|
||||
`;
|
||||
|
||||
export const Prisma = makePrismaBindingClass<BindingConstructor<Prisma>>({
|
||||
typeDefs,
|
||||
});
|
||||
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
|
||||
export type PostOrderByInput =
|
||||
| 'id_ASC'
|
||||
| 'id_DESC'
|
||||
| 'isPublished_ASC'
|
||||
| 'isPublished_DESC'
|
||||
| 'title_ASC'
|
||||
| 'title_DESC'
|
||||
| 'text_ASC'
|
||||
| 'text_DESC'
|
||||
| 'updatedAt_ASC'
|
||||
| 'updatedAt_DESC'
|
||||
| 'createdAt_ASC'
|
||||
| 'createdAt_DESC';
|
||||
|
||||
export type MutationType = 'CREATED' | 'UPDATED' | 'DELETED';
|
||||
|
||||
export interface PostWhereUniqueInput {
|
||||
id?: ID_Input;
|
||||
}
|
||||
|
||||
export interface PostCreateInput {
|
||||
isPublished?: Boolean;
|
||||
title: String;
|
||||
text: String;
|
||||
}
|
||||
|
||||
export interface PostUpdateInput {
|
||||
isPublished?: Boolean;
|
||||
title?: String;
|
||||
text?: String;
|
||||
}
|
||||
|
||||
export interface PostSubscriptionWhereInput {
|
||||
AND?: PostSubscriptionWhereInput[] | PostSubscriptionWhereInput;
|
||||
OR?: PostSubscriptionWhereInput[] | PostSubscriptionWhereInput;
|
||||
NOT?: PostSubscriptionWhereInput[] | PostSubscriptionWhereInput;
|
||||
mutation_in?: MutationType[] | MutationType;
|
||||
updatedFields_contains?: String;
|
||||
updatedFields_contains_every?: String[] | String;
|
||||
updatedFields_contains_some?: String[] | String;
|
||||
node?: PostWhereInput;
|
||||
}
|
||||
|
||||
export interface PostWhereInput {
|
||||
AND?: PostWhereInput[] | PostWhereInput;
|
||||
OR?: PostWhereInput[] | PostWhereInput;
|
||||
NOT?: PostWhereInput[] | PostWhereInput;
|
||||
id?: ID_Input;
|
||||
id_not?: ID_Input;
|
||||
id_in?: ID_Input[] | ID_Input;
|
||||
id_not_in?: ID_Input[] | ID_Input;
|
||||
id_lt?: ID_Input;
|
||||
id_lte?: ID_Input;
|
||||
id_gt?: ID_Input;
|
||||
id_gte?: ID_Input;
|
||||
id_contains?: ID_Input;
|
||||
id_not_contains?: ID_Input;
|
||||
id_starts_with?: ID_Input;
|
||||
id_not_starts_with?: ID_Input;
|
||||
id_ends_with?: ID_Input;
|
||||
id_not_ends_with?: ID_Input;
|
||||
isPublished?: Boolean;
|
||||
isPublished_not?: Boolean;
|
||||
title?: String;
|
||||
title_not?: String;
|
||||
title_in?: String[] | String;
|
||||
title_not_in?: String[] | String;
|
||||
title_lt?: String;
|
||||
title_lte?: String;
|
||||
title_gt?: String;
|
||||
title_gte?: String;
|
||||
title_contains?: String;
|
||||
title_not_contains?: String;
|
||||
title_starts_with?: String;
|
||||
title_not_starts_with?: String;
|
||||
title_ends_with?: String;
|
||||
title_not_ends_with?: String;
|
||||
text?: String;
|
||||
text_not?: String;
|
||||
text_in?: String[] | String;
|
||||
text_not_in?: String[] | String;
|
||||
text_lt?: String;
|
||||
text_lte?: String;
|
||||
text_gt?: String;
|
||||
text_gte?: String;
|
||||
text_contains?: String;
|
||||
text_not_contains?: String;
|
||||
text_starts_with?: String;
|
||||
text_not_starts_with?: String;
|
||||
text_ends_with?: String;
|
||||
text_not_ends_with?: String;
|
||||
}
|
||||
|
||||
/*
|
||||
* An object with an ID
|
||||
|
||||
*/
|
||||
export interface Node {
|
||||
id: ID_Output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Information about pagination in a connection.
|
||||
|
||||
*/
|
||||
export interface PageInfo {
|
||||
hasNextPage: Boolean;
|
||||
hasPreviousPage: Boolean;
|
||||
startCursor?: String;
|
||||
endCursor?: String;
|
||||
}
|
||||
|
||||
export interface BatchPayload {
|
||||
count: Long;
|
||||
}
|
||||
|
||||
export interface PostPreviousValues {
|
||||
id: ID_Output;
|
||||
isPublished: Boolean;
|
||||
title: String;
|
||||
text: String;
|
||||
}
|
||||
|
||||
/*
|
||||
* A connection to a list of items.
|
||||
|
||||
*/
|
||||
export interface PostConnection {
|
||||
pageInfo: PageInfo;
|
||||
edges: PostEdge[];
|
||||
aggregate: AggregatePost;
|
||||
}
|
||||
|
||||
export interface PostSubscriptionPayload {
|
||||
mutation: MutationType;
|
||||
node?: Post;
|
||||
updatedFields?: String[];
|
||||
previousValues?: PostPreviousValues;
|
||||
}
|
||||
|
||||
export interface Post extends Node {
|
||||
id: ID_Output;
|
||||
isPublished: Boolean;
|
||||
title: String;
|
||||
text: String;
|
||||
}
|
||||
|
||||
export interface AggregatePost {
|
||||
count: Int;
|
||||
}
|
||||
|
||||
/*
|
||||
* An edge in a connection.
|
||||
|
||||
*/
|
||||
export interface PostEdge {
|
||||
node: Post;
|
||||
cursor: String;
|
||||
}
|
||||
|
||||
/*
|
||||
The `Boolean` scalar type represents `true` or `false`.
|
||||
*/
|
||||
export type Boolean = boolean;
|
||||
|
||||
/*
|
||||
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
|
||||
*/
|
||||
export type String = string;
|
||||
|
||||
/*
|
||||
The `Long` scalar type represents non-fractional signed whole numeric values.
|
||||
Long can represent values between -(2^63) and 2^63 - 1.
|
||||
*/
|
||||
export type Long = string;
|
||||
|
||||
/*
|
||||
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
|
||||
*/
|
||||
export type ID_Input = string | number;
|
||||
export type ID_Output = string;
|
||||
|
||||
/*
|
||||
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
|
||||
*/
|
||||
export type Int = number;
|
||||
0
sample/22-graphql-prisma/src/prisma/prisma.module.ts
Normal file → Executable file
0
sample/22-graphql-prisma/src/prisma/prisma.module.ts
Normal file → Executable file
17
sample/22-graphql-prisma/src/prisma/prisma.service.ts
Normal file → Executable file
17
sample/22-graphql-prisma/src/prisma/prisma.service.ts
Normal file → Executable file
@@ -1,12 +1,15 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from './prisma.binding';
|
||||
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends Prisma {
|
||||
constructor() {
|
||||
super({
|
||||
endpoint: 'https://eu1.prisma.sh/public-agatepuma-476/my-app/dev',
|
||||
debug: false,
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
async onModuleInit() {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
async enableShutdownHooks(app: INestApplication) {
|
||||
this.$on('beforeExit', async () => {
|
||||
await app.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
0
sample/22-graphql-prisma/tsconfig.build.json
Normal file → Executable file
0
sample/22-graphql-prisma/tsconfig.build.json
Normal file → Executable file
0
sample/22-graphql-prisma/tsconfig.json
Normal file → Executable file
0
sample/22-graphql-prisma/tsconfig.json
Normal file → Executable file
Reference in New Issue
Block a user