Yanluis Ulloa
06/18/2021, 7:03 PMYanluis Ulloa
06/18/2021, 7:05 PMYanluis Ulloa
06/18/2021, 7:06 PMEric Martinez
06/18/2021, 9:41 PMVinaya Sathyanarayana
06/19/2021, 3:19 AMAlan
06/19/2021, 4:16 AMdouble(10,2)
. How Prisma can handle it? if i run prisma migrate
it will override my database to DOUBLE
bb2021
06/19/2021, 5:06 AMupsert
and connectOrCreate
somehow incompatible? 🤔
i've got something along the lines of:
const director = someBoolean ? { connectOrCreate: { create: { name: 'Steven Spielberg' }, where: { name: 'Steven Spielberg' } } } : undefined
const movie = { contentId: 'some_id_here', title: 'Jaws', director }
const upsertResult = await prisma.movie.upsert({ create: movie, update: movie, where: { contentId: movie.contentId } })
// results in "The change you are trying to make would violate the required relation 'DirectorToMovie' between the 'Director' and 'Movie' models.
for reference, the Movie model lists a director as being optional, which is why I'm so confused at it complaining that it would break a required relation. Not sure if it's important, but I'm using sqlite as the underlying db
model Movie {
id Int @id @default(autoincrement())
contentId String
title String
director Director?
}
model Director {
id Int @id @default(autoincrement())
name String @unique
movie Movie @relation(fields: [movieId], references: [id])
movieId Int
}
Ian
06/19/2021, 9:54 AMIan
06/19/2021, 10:29 AMRamesh
06/19/2021, 1:19 PMRamesh
06/19/2021, 1:20 PMMuhammed Kurel
06/19/2021, 1:25 PMCliff
06/20/2021, 12:58 AMFuzzy/Phrase full text search
will be available in prisma schema and client?David Munro
06/20/2021, 3:00 AMTom
06/20/2021, 6:08 AMnpx dotenv -e .env.development prisma db seed --preview-feature
However I still get this error:
Environment variables loaded from .env
Error: This feature is currently in Preview. There may be bugs and it's not recommended to use it in production environments.
Please provide the --preview-feature flag to use this command.
Note that it also uses the wrong env.
Found it: Just separate the two commands with --Azhi Dahaka
06/20/2021, 7:38 AMReinaldy Rafli
06/20/2021, 2:42 PMprisma.schema.findMany()
. I can't seem to find what caused this on the documentation. On the table, there is 3 data already.
"name": "NotFoundError",
"clientVersion": "2.25.0"
Halvor
06/20/2021, 4:30 PMHalvor
06/20/2021, 4:36 PMAlexSPx
06/20/2021, 6:03 PMError: Cannot find module '@prisma/engines'
AlexSPx
06/20/2021, 6:06 PMnpm i @prisma/engine
but still gives the same errorIbrahim
06/20/2021, 10:40 PM// schema
model User {
id Int @id @default(autoincrement())
facebookId String? @unique
googleId String? @unique
profileURL String?
}
//desired type generated on the client
export type User = {
id: number
facebookId?: string | null
googleId?: string | null
profileURL?: string | null
}
// what is really generated
export type User = {
id: number
facebookId: string | null
googleId: string | null
profileURL: string | null
}
Albert Gao
06/21/2021, 12:17 AMNitgo
06/21/2021, 12:36 AMAzhi Dahaka
06/21/2021, 5:28 AMprisma db seed --preview-feature
And I'm following this page: https://www.prisma.io/docs/guides/database/seed-databaseManthan Mallikarjun
06/21/2021, 7:46 AMID
or Id
? For example when adding a relation, do you do postId
or postID
? I personally find myself doing ID
but I noticed that the VSCode extension defaults to Id
jasci
06/21/2021, 8:11 AMgraphql-code-generator
.
1. How to properly ‘type’ the resolvers ?
I typed the resolvers itself with types generated from the graphql-code-generator
for example:
const updateUser: MutationResolvers['updateUser'] = <resolver code>
But the problem is - return type from the resolver ( prisma.user.update
call ) is User (prisma) and it does not include the relations, and here is the conflict ( ’Type ‘User’ is missing the following properties from type ‘User’: adminOf, employeeOf, accounts’ or similar ones ). Basically for every model/type I’ve got 2 type definitions and in many cases they differ.
Here is the User type in the app schema:
type User {
email: String!
firstName: String!
lastName: String!
phone: String
billingAddress: Address
shippingAddress: Address
adminOf: [Company!]!
employeeOf: [Company!]!
accounts: [Account!]!
adminOfVendors: [Vendor]
}
Here is typings for the User model (prisma):
export type User = {
id: string
emailVerificationToken: string | null
passwordResetToken: string | null
superUser: boolean
email: string
firstName: string
lastName: string
password: string
phone: string | null
billingAddress: Prisma.JsonValue | null
shippingAddress: Prisma.JsonValue | null
}
Here is typings for the User type (graphql-code-generator):
export type User = {
__typename?: 'User';
email: Scalars['String'];
firstName: Scalars['String'];
lastName: Scalars['String'];
phone?: Maybe<Scalars['String']>;
billingAddress?: Maybe<Address>;
shippingAddress?: Maybe<Address>;
adminOf: Array<Company>;
employeeOf: Array<Company>;
accounts: Array<Account>;
adminOfVendors?: Maybe<Array<Maybe<Vendor>>>;
};
Maybe there is some universal practice of typing the API with 2 main type files (for the prisma datamodel and app schema) ? I’m new to the typescript.
2. If my app schema defines some fields which are relations (User example):
adminOf: [Company!]!
employeeOf: [Company!]!
accounts: [Account!]!
adminOfVendors: [Vendor]
I do need to use include
in the Prisma Client in every resolver that should return User type? Because they are not returned by default.
3. T*ype resolvers:*
For example I’ve got Company
type and it has field admin
which is of type User.
When I write type resolvers for the Company
type, specifically for the admin
field, do I also need to use include
in it (to get relations of the User) ?
Example:
const resolvers = {
Query: {
// ...
},
Mutation: {
// ...
},
Company: {
admin: (parent, args, context) => {
return context.prisma.company.findUnique({
where: { id: parent.id }
}).user()
// Or something like that
return context.prisma.user.findUnique({
where: { id: parent.userId },
include: {
some_relation_field: true
}
})
}
},
}
Sorry for a lot questions, thank you.David Ilizarov
06/21/2021, 9:04 AMconnect
and update the connecting relation at the same time?
Kinda like how you can use create
to create a new relation.
const createPost = await prisma.post.create({
data: {
title: "How to make croissants",
author: {
create: {
email: "<mailto:viola@prisma.io|viola@prisma.io>",
name: "Viola"
}
}
}
})
I kinda want the same, but like...
const createPost = await prisma.post.create({
data: {
title: "How to make croissants",
author: {
connect: {
id: 10,
data: {
email: "<mailto:viola@prisma.io|viola@prisma.io>",
name: "Viola"
}
}
}
}
})
I know that exact API is not available, but is there something simlar?Albert Gao
06/21/2021, 10:36 AMDregond
06/21/2021, 11:25 AM