From 66fa16a2a3069c42158797f44481cb2f2a06ce33 Mon Sep 17 00:00:00 2001 From: Ahmed Elywa Date: Tue, 24 Nov 2020 17:50:17 +0200 Subject: [PATCH] update to prisma 2.12 --- packages/admin/src/PrismaTable/EditRecord.tsx | 4 ++-- packages/admin/src/PrismaTable/Form/Inputs.tsx | 2 +- packages/admin/src/PrismaTable/QueryDocument.ts | 8 ++++---- packages/cli/package.json | 2 +- .../examples/apollo-nexus-schema/src/context.ts | 4 ++-- .../examples/apollo-sdl-first/src/context.ts | 4 ++-- .../packages/server/src/context.ts | 4 ++-- .../packages/server/src/graphql/Auth.ts | 6 +++--- .../examples/full-stack-nextjs/src/Api/context.ts | 4 ++-- .../full-stack-nextjs/src/Api/graphql/Auth.ts | 6 +++--- packages/generator/package.json | 4 ++-- packages/generator/src/Generators.ts | 2 +- packages/generator/src/admin/createGraphql.ts | 6 +++--- .../graphql-modules/CreateQueriesAndMutations.ts | 8 ++++---- packages/generator/src/nexus-prisma-plugin.ts | 2 +- .../nexus/templates/{findOne.ts => findUnique.ts} | 4 ++-- packages/generator/src/nexus/templates/index.ts | 4 ++-- .../generator/src/sdl/CreateQueriesAndMutations.ts | 8 ++++---- packages/generator/src/sdl/GenerateTypes.ts | 14 ++++++++------ packages/nexus/package.json | 2 +- packages/plugins/package.json | 2 +- packages/types/src/index.ts | 2 +- 22 files changed, 52 insertions(+), 50 deletions(-) rename packages/generator/src/nexus/templates/{findOne.ts => findUnique.ts} (70%) diff --git a/packages/admin/src/PrismaTable/EditRecord.tsx b/packages/admin/src/PrismaTable/EditRecord.tsx index ff2e0348..34d56d6e 100644 --- a/packages/admin/src/PrismaTable/EditRecord.tsx +++ b/packages/admin/src/PrismaTable/EditRecord.tsx @@ -56,12 +56,12 @@ const EditRecord: React.FC = ({ }); } - const record = data ? data[`findOne${model}`] : {}; + const record = data ? data[`findUnique${model}`] : {}; const tabs = modelObject?.fields.filter( (field) => field.kind === 'object' && field.list && field.read, ); - if (!loading && data && !data[`findOne${model}`] && modelObject) + if (!loading && data && !data[`findUnique${model}`] && modelObject) push(pagesPath + model); const onUpdateCancel = diff --git a/packages/admin/src/PrismaTable/Form/Inputs.tsx b/packages/admin/src/PrismaTable/Form/Inputs.tsx index 604f098b..98708eb5 100644 --- a/packages/admin/src/PrismaTable/Form/Inputs.tsx +++ b/packages/admin/src/PrismaTable/Form/Inputs.tsx @@ -195,7 +195,7 @@ const defaultInputs: Omit = { const [getData, { data, loading }] = useLazyQuery( queryDocument(models, field.type, true), ); - const result = data ? data[`findOne${field.type}`] : {}; + const result = data ? data[`findUnique${field.type}`] : {}; if ( state && diff --git a/packages/admin/src/PrismaTable/QueryDocument.ts b/packages/admin/src/PrismaTable/QueryDocument.ts index 5db5f47b..453fb223 100644 --- a/packages/admin/src/PrismaTable/QueryDocument.ts +++ b/packages/admin/src/PrismaTable/QueryDocument.ts @@ -69,14 +69,14 @@ const allScalar = (model?: SchemaModel) => { export const queryDocument = ( models: SchemaModel[], modelName: string, - findOne = false, + findUnique = false, update = false, ) => { const fields = getFields(models, modelName, update); - if (findOne) { + if (findUnique) { return tag` -query findOne${modelName}($where: ${modelName}WhereUniqueInput!) { - findOne${modelName}(where: $where) { +query findUnique${modelName}($where: ${modelName}WhereUniqueInput!) { + findUnique${modelName}(where: $where) { ${fields} } } diff --git a/packages/cli/package.json b/packages/cli/package.json index cc2e0fda..b7a5314c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -15,7 +15,7 @@ "@paljs/display": "^2.5.4", "@paljs/generator": "^2.6.2", "@paljs/schema": "^2.6.2", - "@prisma/sdk": "2.11.0", + "@prisma/sdk": "2.12.0", "cross-spawn": "^7.0.3", "enquirer": "^2.3.6", "fs-extra": "^9.0.1", diff --git a/packages/create/examples/apollo-nexus-schema/src/context.ts b/packages/create/examples/apollo-nexus-schema/src/context.ts index 93e4b44a..b0b0348c 100644 --- a/packages/create/examples/apollo-nexus-schema/src/context.ts +++ b/packages/create/examples/apollo-nexus-schema/src/context.ts @@ -1,8 +1,8 @@ -import { PrismaClient, PrismaClientOptions } from '@prisma/client' +import { PrismaClient, Prisma as PrismaTypes } from '@prisma/client' import { PrismaDelete, onDeleteArgs } from '@paljs/plugins' class Prisma extends PrismaClient { - constructor(options?: PrismaClientOptions) { + constructor(options?: PrismaTypes.PrismaClientOptions) { super(options) } diff --git a/packages/create/examples/apollo-sdl-first/src/context.ts b/packages/create/examples/apollo-sdl-first/src/context.ts index 59823135..f33d82f1 100644 --- a/packages/create/examples/apollo-sdl-first/src/context.ts +++ b/packages/create/examples/apollo-sdl-first/src/context.ts @@ -1,8 +1,8 @@ -import { PrismaClient, PrismaClientOptions } from '@prisma/client'; +import { PrismaClient, Prisma as PrismaTypes } from '@prisma/client'; import { PrismaDelete, onDeleteArgs } from '@paljs/plugins'; class Prisma extends PrismaClient { - constructor(options?: PrismaClientOptions) { + constructor(options?: PrismaTypes.PrismaClientOptions) { super(options); } diff --git a/packages/create/examples/full-stack-gatsbyjs/packages/server/src/context.ts b/packages/create/examples/full-stack-gatsbyjs/packages/server/src/context.ts index 8c6583c2..55570bef 100644 --- a/packages/create/examples/full-stack-gatsbyjs/packages/server/src/context.ts +++ b/packages/create/examples/full-stack-gatsbyjs/packages/server/src/context.ts @@ -1,10 +1,10 @@ -import { PrismaClient, PrismaClientOptions } from '@prisma/client' +import { PrismaClient, Prisma as PrismaTypes } from '@prisma/client' import { ExpressContext } from 'apollo-server-express/dist/ApolloServer' import { PrismaDelete, onDeleteArgs } from '@paljs/plugins' import { getUserId } from './utils' class Prisma extends PrismaClient { - constructor(options?: PrismaClientOptions) { + constructor(options?: PrismaTypes.PrismaClientOptions) { super(options) } diff --git a/packages/create/examples/full-stack-gatsbyjs/packages/server/src/graphql/Auth.ts b/packages/create/examples/full-stack-gatsbyjs/packages/server/src/graphql/Auth.ts index d470b539..aa2281c1 100644 --- a/packages/create/examples/full-stack-gatsbyjs/packages/server/src/graphql/Auth.ts +++ b/packages/create/examples/full-stack-gatsbyjs/packages/server/src/graphql/Auth.ts @@ -19,7 +19,7 @@ export const AuthQueries = extendType({ nullable: true, resolve: async (_, __, { prisma, select, userId }) => { if (!userId) return null - return prisma.user.findOne({ + return prisma.user.findUnique({ where: { id: userId, }, @@ -63,7 +63,7 @@ export const AuthMutations = extendType({ password: stringArg({ nullable: false }), }, resolve: async (_parent, { email, password }, ctx) => { - const user = await ctx.prisma.user.findOne({ + const user = await ctx.prisma.user.findUnique({ where: { email, }, @@ -90,7 +90,7 @@ export const AuthMutations = extendType({ resolve: async (_, { currentPassword, password }, ctx) => { if (currentPassword && password) { // get current user and verify currentPassword before changing; - const user = await ctx.prisma.user.findOne({ + const user = await ctx.prisma.user.findUnique({ where: { id: ctx.userId }, select: { password: true }, }) diff --git a/packages/create/examples/full-stack-nextjs/src/Api/context.ts b/packages/create/examples/full-stack-nextjs/src/Api/context.ts index e8a5df07..8755dd4a 100644 --- a/packages/create/examples/full-stack-nextjs/src/Api/context.ts +++ b/packages/create/examples/full-stack-nextjs/src/Api/context.ts @@ -1,10 +1,10 @@ -import { PrismaClient, PrismaClientOptions } from '@prisma/client' +import { PrismaClient, Prisma as PrismaTypes } from '@prisma/client' import { PrismaDelete, onDeleteArgs } from '@paljs/plugins' import { NextApiRequest, NextApiResponse } from 'next' import { getUserId } from './utils' class Prisma extends PrismaClient { - constructor(options?: PrismaClientOptions) { + constructor(options?: PrismaTypes.PrismaClientOptions) { super(options) } diff --git a/packages/create/examples/full-stack-nextjs/src/Api/graphql/Auth.ts b/packages/create/examples/full-stack-nextjs/src/Api/graphql/Auth.ts index ae9b743f..ae1602a3 100644 --- a/packages/create/examples/full-stack-nextjs/src/Api/graphql/Auth.ts +++ b/packages/create/examples/full-stack-nextjs/src/Api/graphql/Auth.ts @@ -13,7 +13,7 @@ export const AuthQueries = extendType({ nullable: true, resolve: async (_, __, { prisma, select, userId }) => { if (!userId) return null - return prisma.user.findOne({ + return prisma.user.findUnique({ where: { id: userId, }, @@ -64,7 +64,7 @@ export const AuthMutations = extendType({ password: stringArg({ nullable: false }), }, resolve: async (_parent, { email, password }, ctx) => { - const user = await ctx.prisma.user.findOne({ + const user = await ctx.prisma.user.findUnique({ where: { email, }, @@ -114,7 +114,7 @@ export const AuthMutations = extendType({ resolve: async (_, { currentPassword, password }, ctx) => { if (currentPassword && password) { // get current user and verify currentPassword before changing; - const user = await ctx.prisma.user.findOne({ + const user = await ctx.prisma.user.findUnique({ where: { id: ctx.userId }, select: { password: true }, }) diff --git a/packages/generator/package.json b/packages/generator/package.json index 05d0fb8b..43856dc7 100644 --- a/packages/generator/package.json +++ b/packages/generator/package.json @@ -22,13 +22,13 @@ }, "dependencies": { "@paljs/types": "^2.5.4", - "@prisma/sdk": "2.11.0", + "@prisma/sdk": "2.12.0", "pkg-dir": "^5.0.0", "pluralize": "^8.0.0", "prettier": "^2.1.2" }, "devDependencies": { - "@prisma/client": "2.11.0", + "@prisma/client": "2.12.0", "@types/node": "14.14.7", "@types/pluralize": "^0.0.29", "@types/prettier": "2.1.5", diff --git a/packages/generator/src/Generators.ts b/packages/generator/src/Generators.ts index 9b2b4799..d1366017 100644 --- a/packages/generator/src/Generators.ts +++ b/packages/generator/src/Generators.ts @@ -20,7 +20,7 @@ export class Generators { protected isJS?: boolean = false; protected queries: Query[] = [ - 'findOne', + 'findUnique', 'findFirst', 'findMany', 'findCount', diff --git a/packages/generator/src/admin/createGraphql.ts b/packages/generator/src/admin/createGraphql.ts index f7a580d1..9ffbca40 100644 --- a/packages/generator/src/admin/createGraphql.ts +++ b/packages/generator/src/admin/createGraphql.ts @@ -51,10 +51,10 @@ ${ ) ? ` ${ - !excludeQueriesAndMutations.includes('findOne') + !excludeQueriesAndMutations.includes('findUnique') ? ` -query findOne${model.name}($where: ${model.name}WhereUniqueInput!) { - findOne${model.name}(where: $where) { +query findUnique${model.name}($where: ${model.name}WhereUniqueInput!) { + findUnique${model.name}(where: $where) { ...${model.name} } }` diff --git a/packages/generator/src/graphql-modules/CreateQueriesAndMutations.ts b/packages/generator/src/graphql-modules/CreateQueriesAndMutations.ts index 84e2d835..e36abcc8 100644 --- a/packages/generator/src/graphql-modules/CreateQueriesAndMutations.ts +++ b/packages/generator/src/graphql-modules/CreateQueriesAndMutations.ts @@ -17,12 +17,12 @@ export function createQueriesAndMutations( }, }; - if (!exclude.includes('findOne')) { + if (!exclude.includes('findUnique')) { operations.queries.type += ` - findOne${name}(where: ${name}WhereUniqueInput!): ${name}`; + findUnique${name}(where: ${name}WhereUniqueInput!): ${name}`; operations.queries.resolver += ` - findOne${name}: (_parent, args, { injector }: GraphQLModules.Context) => { - return injector.get(PrismaProvider).${model}.findOne(args); + findUnique${name}: (_parent, args, { injector }: GraphQLModules.Context) => { + return injector.get(PrismaProvider).${model}.findUnique(args); },`; } diff --git a/packages/generator/src/nexus-prisma-plugin.ts b/packages/generator/src/nexus-prisma-plugin.ts index 819b9f7a..4b11c493 100644 --- a/packages/generator/src/nexus-prisma-plugin.ts +++ b/packages/generator/src/nexus-prisma-plugin.ts @@ -61,7 +61,7 @@ export class GenerateNexusPrismaPlugin extends Generators { .filter((item) => !exclude.includes(item)) .forEach((item) => { switch (item) { - case 'findOne': + case 'findUnique': fileContent.push(`t.crud.${modelName.singular}()`); break; case 'findMany': diff --git a/packages/generator/src/nexus/templates/findOne.ts b/packages/generator/src/nexus/templates/findUnique.ts similarity index 70% rename from packages/generator/src/nexus/templates/findOne.ts rename to packages/generator/src/nexus/templates/findUnique.ts index c2be7351..d05392ab 100644 --- a/packages/generator/src/nexus/templates/findOne.ts +++ b/packages/generator/src/nexus/templates/findUnique.ts @@ -1,7 +1,7 @@ export default ` #{import} -#{exportTs}const #{Model}FindOneQuery = queryField('findOne#{Model}', { +#{exportTs}const #{Model}FindUniqueQuery = queryField('findUnique#{Model}', { type: '#{Model}', nullable: true, args: { @@ -11,7 +11,7 @@ export default ` }), }, resolve(_parent, { where }, { prisma, select }) { - return prisma.#{model}.findOne({ + return prisma.#{model}.findUnique({ where, ...select, }) diff --git a/packages/generator/src/nexus/templates/index.ts b/packages/generator/src/nexus/templates/index.ts index 14d0bf71..b9883888 100644 --- a/packages/generator/src/nexus/templates/index.ts +++ b/packages/generator/src/nexus/templates/index.ts @@ -1,4 +1,4 @@ -import findOne from './findOne'; +import findUnique from './findUnique'; import findFirst from './findFirst'; import findMany from './findMany'; import findCount from './findCount'; @@ -12,7 +12,7 @@ import aggregate from './aggregate'; import { QueriesAndMutations } from '@paljs/types'; const crud: { [key in QueriesAndMutations]: string } = { - findOne, + findUnique, findFirst, findMany, findCount, diff --git a/packages/generator/src/sdl/CreateQueriesAndMutations.ts b/packages/generator/src/sdl/CreateQueriesAndMutations.ts index ee79211a..8ff7c87a 100644 --- a/packages/generator/src/sdl/CreateQueriesAndMutations.ts +++ b/packages/generator/src/sdl/CreateQueriesAndMutations.ts @@ -17,12 +17,12 @@ export function createQueriesAndMutations( }, }; - if (!exclude.includes('findOne')) { + if (!exclude.includes('findUnique')) { operations.queries.type += ` - findOne${name}(where: ${name}WhereUniqueInput!): ${name}`; + findUnique${name}(where: ${name}WhereUniqueInput!): ${name}`; operations.queries.resolver += ` - findOne${name}: (_parent, args, {prisma}) => { - return prisma.${model}.findOne(args) + findUnique${name}: (_parent, args, {prisma}) => { + return prisma.${model}.findUnique(args) },`; } diff --git a/packages/generator/src/sdl/GenerateTypes.ts b/packages/generator/src/sdl/GenerateTypes.ts index ed0eb45f..3ae273a0 100644 --- a/packages/generator/src/sdl/GenerateTypes.ts +++ b/packages/generator/src/sdl/GenerateTypes.ts @@ -2,7 +2,7 @@ import { DMMF } from '../schema'; export class GenerateTypes { code: string[] = [ - `import * as Prisma from '@prisma/client'`, + `import * as Client from '@prisma/client'`, `import { Context } from './context'`, `import { GraphQLResolveInfo } from 'graphql';`, `type Resolver = (parent: T,args: A, context: Context, info: GraphQLResolveInfo) => Promise;`, @@ -42,7 +42,9 @@ export class GenerateTypes { .toString() .replace('Aggregate', '')}AggregateType<${options.type}Args>` : options.type; - return `${!input ? 'Prisma.' : ''}${type}${options.isList ? '[]' : ''}`; + return `${!input ? 'Client.Prisma.' : ''}${type}${ + options.isList ? '[]' : '' + }`; } } @@ -130,10 +132,10 @@ export class GenerateTypes { .replace('Aggregate', ''); args.push( `count?: true`, - `avg?: Prisma.${modelName}AvgAggregateInputType`, - `sum?: Prisma.${modelName}SumAggregateInputType`, - `min?: Prisma.${modelName}MinAggregateInputType`, - `max?: Prisma.${modelName}MaxAggregateInputType`, + `avg?: Client.Prisma.${modelName}AvgAggregateInputType`, + `sum?: Client.Prisma.${modelName}SumAggregateInputType`, + `min?: Client.Prisma.${modelName}MinAggregateInputType`, + `max?: Client.Prisma.${modelName}MaxAggregateInputType`, ); } args.push('}'); diff --git a/packages/nexus/package.json b/packages/nexus/package.json index 465af075..c46c1724 100644 --- a/packages/nexus/package.json +++ b/packages/nexus/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "@nexus/schema": "0.18.0", - "@prisma/client": "2.11.0", + "@prisma/client": "2.12.0", "@types/lowdb": "1.0.9", "typescript": "4.0.5" }, diff --git a/packages/plugins/package.json b/packages/plugins/package.json index 7cddfd5b..37e8d917 100644 --- a/packages/plugins/package.json +++ b/packages/plugins/package.json @@ -29,7 +29,7 @@ "access": "public" }, "devDependencies": { - "@prisma/client": "2.11.0", + "@prisma/client": "2.12.0", "graphql": "^15.4.0", "typescript": "4.0.5" }, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index b12dd7bc..3603b67a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -88,7 +88,7 @@ export interface Options { } export type Query = - | 'findOne' + | 'findUnique' | 'findFirst' | 'findMany' | 'findCount'