From 67880cbaf1936c95896d2b6d0d657f8af31afa05 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Wed, 15 Dec 2021 00:03:05 -0800 Subject: [PATCH] generate prisma clients into custom locations to avoid conflicts --- examples/prisma-relay/.gitignore | 2 + examples/prisma-relay/prisma/schema.prisma | 6 +- examples/prisma-relay/prisma/seed.ts | 2 +- examples/prisma-relay/prisma/tsconfig.json | 3 - examples/prisma-relay/src/db.ts | 2 +- examples/prisma-relay/tsconfig.json | 1 + examples/prisma/.gitignore | 2 + examples/prisma/prisma/schema.prisma | 6 +- examples/prisma/prisma/seed.ts | 2 +- examples/prisma/prisma/tsconfig.json | 3 - examples/prisma/src/db.ts | 2 +- examples/prisma/tsconfig.json | 1 + packages/plugin-prisma/prisma/schema.prisma | 3 +- packages/plugin-prisma/prisma/seed.ts | 2 +- packages/plugin-prisma/src/refs.ts | 2 +- packages/plugin-prisma/tests/.gitignore | 2 + .../plugin-prisma/tests/example/builder.ts | 2 +- packages/plugin-prisma/tests/generated.ts | 79 ------------------- 18 files changed, 27 insertions(+), 95 deletions(-) create mode 100644 examples/prisma-relay/.gitignore delete mode 100644 examples/prisma-relay/prisma/tsconfig.json create mode 100644 examples/prisma/.gitignore delete mode 100644 examples/prisma/prisma/tsconfig.json create mode 100644 packages/plugin-prisma/tests/.gitignore delete mode 100644 packages/plugin-prisma/tests/generated.ts diff --git a/examples/prisma-relay/.gitignore b/examples/prisma-relay/.gitignore new file mode 100644 index 000000000..e1e725bf8 --- /dev/null +++ b/examples/prisma-relay/.gitignore @@ -0,0 +1,2 @@ +prisma/generated.ts +prisma/client/* \ No newline at end of file diff --git a/examples/prisma-relay/prisma/schema.prisma b/examples/prisma-relay/prisma/schema.prisma index 144da80a7..f5ae2442d 100644 --- a/examples/prisma-relay/prisma/schema.prisma +++ b/examples/prisma-relay/prisma/schema.prisma @@ -5,12 +5,16 @@ datasource db { generator client { provider = "prisma-client-js" + // Generate into custom location because this repo has multiple prisma schemas + output = "./client" } generator giraphql { // In a real app use `provider = "prisma-giraphql-types"` instead provider = "ts-node node_modules/@giraphql/plugin-prisma/src/generator.ts" - clientOutput = "@prisma/client" + // Match client output location from above + clientOutput = "./client" + output = "./generated.ts" } model User { diff --git a/examples/prisma-relay/prisma/seed.ts b/examples/prisma-relay/prisma/seed.ts index 32d24190a..c9a9efb9a 100644 --- a/examples/prisma-relay/prisma/seed.ts +++ b/examples/prisma-relay/prisma/seed.ts @@ -1,7 +1,7 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-magic-numbers */ import faker from 'faker'; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from './client'; const prisma = new PrismaClient(); diff --git a/examples/prisma-relay/prisma/tsconfig.json b/examples/prisma-relay/prisma/tsconfig.json deleted file mode 100644 index a5754b591..000000000 --- a/examples/prisma-relay/prisma/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../../tsconfig.options.json" -} \ No newline at end of file diff --git a/examples/prisma-relay/src/db.ts b/examples/prisma-relay/src/db.ts index 4a09be7f3..52cadf215 100644 --- a/examples/prisma-relay/src/db.ts +++ b/examples/prisma-relay/src/db.ts @@ -1,3 +1,3 @@ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/client'; export const db = new PrismaClient(); diff --git a/examples/prisma-relay/tsconfig.json b/examples/prisma-relay/tsconfig.json index 9dd284743..8b3d8f441 100644 --- a/examples/prisma-relay/tsconfig.json +++ b/examples/prisma-relay/tsconfig.json @@ -9,6 +9,7 @@ "allowSyntheticDefaultImports": true }, "include": [ + "prisma/*.ts", "src/**/*" ] } \ No newline at end of file diff --git a/examples/prisma/.gitignore b/examples/prisma/.gitignore new file mode 100644 index 000000000..e1e725bf8 --- /dev/null +++ b/examples/prisma/.gitignore @@ -0,0 +1,2 @@ +prisma/generated.ts +prisma/client/* \ No newline at end of file diff --git a/examples/prisma/prisma/schema.prisma b/examples/prisma/prisma/schema.prisma index 144da80a7..f5ae2442d 100644 --- a/examples/prisma/prisma/schema.prisma +++ b/examples/prisma/prisma/schema.prisma @@ -5,12 +5,16 @@ datasource db { generator client { provider = "prisma-client-js" + // Generate into custom location because this repo has multiple prisma schemas + output = "./client" } generator giraphql { // In a real app use `provider = "prisma-giraphql-types"` instead provider = "ts-node node_modules/@giraphql/plugin-prisma/src/generator.ts" - clientOutput = "@prisma/client" + // Match client output location from above + clientOutput = "./client" + output = "./generated.ts" } model User { diff --git a/examples/prisma/prisma/seed.ts b/examples/prisma/prisma/seed.ts index 32d24190a..c9a9efb9a 100644 --- a/examples/prisma/prisma/seed.ts +++ b/examples/prisma/prisma/seed.ts @@ -1,7 +1,7 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-magic-numbers */ import faker from 'faker'; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from './client'; const prisma = new PrismaClient(); diff --git a/examples/prisma/prisma/tsconfig.json b/examples/prisma/prisma/tsconfig.json deleted file mode 100644 index a5754b591..000000000 --- a/examples/prisma/prisma/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../../tsconfig.options.json" -} \ No newline at end of file diff --git a/examples/prisma/src/db.ts b/examples/prisma/src/db.ts index 4a09be7f3..52cadf215 100644 --- a/examples/prisma/src/db.ts +++ b/examples/prisma/src/db.ts @@ -1,3 +1,3 @@ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/client'; export const db = new PrismaClient(); diff --git a/examples/prisma/tsconfig.json b/examples/prisma/tsconfig.json index 9dd284743..8b3d8f441 100644 --- a/examples/prisma/tsconfig.json +++ b/examples/prisma/tsconfig.json @@ -9,6 +9,7 @@ "allowSyntheticDefaultImports": true }, "include": [ + "prisma/*.ts", "src/**/*" ] } \ No newline at end of file diff --git a/packages/plugin-prisma/prisma/schema.prisma b/packages/plugin-prisma/prisma/schema.prisma index 838c62468..a71479015 100644 --- a/packages/plugin-prisma/prisma/schema.prisma +++ b/packages/plugin-prisma/prisma/schema.prisma @@ -7,11 +7,12 @@ datasource db { generator client { provider = "prisma-client-js" + output = "../tests/client" } generator giraphql { provider = "ts-node ./src/generator.ts" - clientOutput = "@prisma/client" + clientOutput = "../tests/client" output = "../tests/generated.ts" } diff --git a/packages/plugin-prisma/prisma/seed.ts b/packages/plugin-prisma/prisma/seed.ts index ee2f27b7e..e6f4c1a3c 100644 --- a/packages/plugin-prisma/prisma/seed.ts +++ b/packages/plugin-prisma/prisma/seed.ts @@ -1,6 +1,6 @@ // @ts-ignore import faker from 'faker'; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../tests/client'; const prisma = new PrismaClient(); diff --git a/packages/plugin-prisma/src/refs.ts b/packages/plugin-prisma/src/refs.ts index 533b7e67f..8c173be30 100644 --- a/packages/plugin-prisma/src/refs.ts +++ b/packages/plugin-prisma/src/refs.ts @@ -1,5 +1,5 @@ import { ObjectRef, SchemaTypes } from '@giraphql/core'; -import { Prisma } from '@prisma/client'; +import { Prisma } from '../tests/client'; import { PrismaDelegate } from './types'; export const refMap = new WeakMap>>(); diff --git a/packages/plugin-prisma/tests/.gitignore b/packages/plugin-prisma/tests/.gitignore new file mode 100644 index 000000000..a6bf5829f --- /dev/null +++ b/packages/plugin-prisma/tests/.gitignore @@ -0,0 +1,2 @@ +generated.ts +client/* \ No newline at end of file diff --git a/packages/plugin-prisma/tests/example/builder.ts b/packages/plugin-prisma/tests/example/builder.ts index 9fc6adf19..327c5b301 100644 --- a/packages/plugin-prisma/tests/example/builder.ts +++ b/packages/plugin-prisma/tests/example/builder.ts @@ -1,9 +1,9 @@ import SchemaBuilder from '@giraphql/core'; import ErrorsPlugin from '@giraphql/plugin-errors'; import RelayPlugin from '@giraphql/plugin-relay'; -import { PrismaClient } from '@prisma/client'; // eslint-disable-next-line import/no-named-as-default import PrismaPlugin from '../../src'; +import { PrismaClient } from '../client'; import PrismaTypes from '../generated'; export const prisma = new PrismaClient({ diff --git a/packages/plugin-prisma/tests/generated.ts b/packages/plugin-prisma/tests/generated.ts deleted file mode 100644 index 1f2b6620f..000000000 --- a/packages/plugin-prisma/tests/generated.ts +++ /dev/null @@ -1,79 +0,0 @@ -import type { Prisma, Post, Comment, Profile, User, Unrelated } from "@prisma/client"; -export default interface PrismaTypes { - Post: { - Shape: Post; - Include: Prisma.PostInclude; - Where: Prisma.PostWhereUniqueInput; - Fields: "author" | "comments"; - ListRelations: "comments"; - Relations: { - author: { - Shape: User; - Types: PrismaTypes["User"]; - }; - comments: { - Shape: Comment[]; - Types: PrismaTypes["Comment"]; - }; - }; - }; - Comment: { - Shape: Comment; - Include: Prisma.CommentInclude; - Where: Prisma.CommentWhereUniqueInput; - Fields: "author" | "post"; - ListRelations: never; - Relations: { - author: { - Shape: User; - Types: PrismaTypes["User"]; - }; - post: { - Shape: Post; - Types: PrismaTypes["Post"]; - }; - }; - }; - Profile: { - Shape: Profile; - Include: Prisma.ProfileInclude; - Where: Prisma.ProfileWhereUniqueInput; - Fields: "user"; - ListRelations: never; - Relations: { - user: { - Shape: User; - Types: PrismaTypes["User"]; - }; - }; - }; - User: { - Shape: User; - Include: Prisma.UserInclude; - Where: Prisma.UserWhereUniqueInput; - Fields: "posts" | "comments" | "profile"; - ListRelations: "posts" | "comments"; - Relations: { - posts: { - Shape: Post[]; - Types: PrismaTypes["Post"]; - }; - comments: { - Shape: Comment[]; - Types: PrismaTypes["Comment"]; - }; - profile: { - Shape: Profile | null; - Types: PrismaTypes["Profile"]; - }; - }; - }; - Unrelated: { - Shape: Unrelated; - Include: never; - Where: Prisma.UnrelatedWhereUniqueInput; - Fields: never; - ListRelations: never; - Relations: {}; - }; -} \ No newline at end of file