Skip to content

Commit

Permalink
update to prisma 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedElywa committed Nov 24, 2020
1 parent 2f4a561 commit 66fa16a
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 50 deletions.
4 changes: 2 additions & 2 deletions packages/admin/src/PrismaTable/EditRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ const EditRecord: React.FC<EditRecordProps> = ({
});
}

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 =
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/PrismaTable/Form/Inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const defaultInputs: Omit<FormInputs, 'Upload'> = {
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 &&
Expand Down
8 changes: 4 additions & 4 deletions packages/admin/src/PrismaTable/QueryDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/create/examples/apollo-nexus-schema/src/context.ts
Original file line number Diff line number Diff line change
@@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/create/examples/apollo-sdl-first/src/context.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand All @@ -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 },
})
Expand Down
4 changes: 2 additions & 2 deletions packages/create/examples/full-stack-nextjs/src/Api/context.ts
Original file line number Diff line number Diff line change
@@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 },
})
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/Generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Generators {
protected isJS?: boolean = false;

protected queries: Query[] = [
'findOne',
'findUnique',
'findFirst',
'findMany',
'findCount',
Expand Down
6 changes: 3 additions & 3 deletions packages/generator/src/admin/createGraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/nexus-prisma-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -11,7 +11,7 @@ export default `
}),
},
resolve(_parent, { where }, { prisma, select }) {
return prisma.#{model}.findOne({
return prisma.#{model}.findUnique({
where,
...select,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/nexus/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import findOne from './findOne';
import findUnique from './findUnique';
import findFirst from './findFirst';
import findMany from './findMany';
import findCount from './findCount';
Expand All @@ -12,7 +12,7 @@ import aggregate from './aggregate';
import { QueriesAndMutations } from '@paljs/types';

const crud: { [key in QueriesAndMutations]: string } = {
findOne,
findUnique,
findFirst,
findMany,
findCount,
Expand Down
8 changes: 4 additions & 4 deletions packages/generator/src/sdl/CreateQueriesAndMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},`;
}

Expand Down
14 changes: 8 additions & 6 deletions packages/generator/src/sdl/GenerateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends {}, A extends {}, R extends any> = (parent: T,args: A, context: Context, info: GraphQLResolveInfo) => Promise<R>;`,
Expand Down Expand Up @@ -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 ? '[]' : ''
}`;
}
}

Expand Down Expand Up @@ -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('}');
Expand Down
2 changes: 1 addition & 1 deletion packages/nexus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface Options {
}

export type Query =
| 'findOne'
| 'findUnique'
| 'findFirst'
| 'findMany'
| 'findCount'
Expand Down

0 comments on commit 66fa16a

Please sign in to comment.