https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • e

    Evan Kolb

    09/30/2021, 3:40 PM
    Hi, my team is looking to migrate from prisma1 to prisma2 and a core pillar of our stack is using graphql-codegen to generate the typescript for both our prisma and graphql schemas. I noticed that in prisma2 the schema.prisma is generated directly into typescript and sent to the node_modules/.prisma/client folder and there is no longer a generated graphql file. Currently we are importing that generated prisma graphql file into our graphql.schema file which is then used to generate our typescript types using the codegen tool. My fear is that if we upgrade to prisma2, we would lose out on being able to reference the prisma types in the graphql.schema and wouldn't be able to generate our types. Are there any good workarounds for this?
    r
    • 2
    • 2
  • t

    Torrino

    09/30/2021, 4:38 PM
    Apologies if my question is a bit too much but I'm currently redesigning my database for a game I'm working on and my question is; Is it possible to somehow represent the table
    rpg_inventory
    found here https://stackoverflow.com/a/48054742 using Prisma? The 3rd column references an ID of a different table but which table? well it depends on the 2nd column id (
    type_reference
    ) and I'm confused as to how to choose which prisma Model is being referenced? Any help or someone I could exchange some thoughts with would be greatly appreciated
  • e

    Elie Steinbock

    10/01/2021, 12:46 AM
    just watched this video:

    https://www.youtube.com/watch?v=iyGZ8JFPgoY&list=RDCMUCptAHlN1gdwD89tFM3ENb6w&start_radio=1&rv=iyGZ8JFPgoY&t=1643▾

    how can i get access to data proxy?
    r
    • 2
    • 1
  • m

    Moh

    10/01/2021, 5:14 AM
    Hey guys, I have a quick Q - brain is a little fried. I have two tables with a one-to-many relationship. For eg... Table 1 (parent): name, age, children Table 2 (children) name, age, favourite_number parent_id How can I update table 1 to set parent_id on table 2 when the request sends a parent object with an array of children, and remove it from any existing children if it wasn't in the request array. eg: { name: "Parent name", age: 30, children: { name: "Child name", age: 12, favourite_number: 4 } Should set that childs parent_id to the parents ID, and any other entry in the children table that may have had that parents ID to null Hope that's clear...
    r
    • 2
    • 1
  • u

    user

    10/01/2021, 10:35 AM
    Next.js GraphQL API using Apollo Server 3 and Prisma

    https://www.youtube.com/watch?v=RJpevpbC4YY▾

    In this video, you'll learn how to build a GraphQL API in a Next.js app using Apollo Server 3. Timestamps: 00:00 - 00:50 Installing apollo-server-micro, graphql & micro-cors 00:50 - 03:47 Defining a GraphQL schema 03:47 - 05:13 Including a database URL + Seeding the database 5:13 - 11:45 Creating the GraphQL endpoint 11:45 - 14:25 Taking a look at Apollo Studio 14:25 - 17:35 Initializing Prisma Client 17:35 - 19:04 Updating the resolver 19:04 - 21:30 Creating the GraphQL context Useful links: • Apollo Studio: https://studio.apollographql.com/ • Apollo Server 3: apollographql.com/docs/apollo-server/ • Initializing Prisma Client in a Next.js Project: https://www.prisma.io/docs/support/help-articles/nextjs-prisma-client-dev-practices#problem • GraphQL spec: https://graphql.org • Resolver arguments: https://www.apollographql.com/docs/apollo-server/data/resolvers/#resolver-arguments • GitHub repo: https://github.com/m-abdelwahab/awesome-links • Part 2 blog post: https://prisma.io/blog/fullstack-nextjs-graphql-prisma-2-fwpc6ds155 • Part 1 blog post: https://prisma.io/blog/fullstack-nextjs-graphql-prisma-oklidw1rhw 👉 Next video: Building a GraphQL API using Nexus, Prisma and Next.js -

    https://www.youtube.com/watch?v=auckcBaZifw&list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&index=13&pp=sAQB▾

    👉 Previous video: REST vs. GraphQL -

    https://www.youtube.com/watch?v=f1KxJi-2PFo&list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&index=11&pp=sAQB▾

    👉 Check out the full playlist: https://www.youtube.com/playlist?list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk
    🙌 2
  • c

    Cree Jee

    10/01/2021, 12:47 PM
    I have some Question for prisma2 join table. and also one issue Schema:
    Copy code
    //other
    model LayoutSetting {
      id                     Int                        @id @default(autoincrement())
      relatedLayoutToProduct LayoutSettingLinkProduct[]
    }
    
    model LayoutSettingLinkProduct {
      layoutId  Int
      productId Int
      order     Int
      layout    LayoutSetting @relation(fields: [layoutId], references: [id])
      product   Product       @relation(fields: [productId], references: [id])
    
      @@id([layoutId, productId])
      @@index([order])
    }
    
    model Product {
      id                     Int                        @id @default(autoincrement())
      relatedLayoutToProduct LayoutSettingLinkProduct[]
    }
    After executing many transactions and queries as a batch program, the following errors occurred.
    Copy code
    Invalid `prisma.layoutSettingLinkProduct.deleteMany()` invocation:
    
    
      Failed to validate the query: `Field does not exist on enclosing type.` at `Mutation.deleteManyLayoutSettingLinkProduct`
        at cb (/Users/creejee/*****/renewal-project/*********/node_modules/@*****************/appsync-schema/prisma/generated/client/runtime/index.js:36952:17)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async upsertLayout (/Users/creejee/*****/renewal-project/*********/util/batch/appsync/insertProductData.js:59:9)
        at async task (/Users/creejee/*****/renewal-project/*********/util/batch/appsync/insertProductData.js:496:9) {
      code: 'P2009',
      clientVersion: '3.1.1',
      meta: {
        query_validation_error: 'Field does not exist on enclosing type.',
        query_position: 'Mutation.deleteManyLayoutSettingLinkProduct'
      }
    }
    The following sample code was written for problem trouble shooting, and there was no error at this time.
    Copy code
    const layout = await prismaClient.layoutSetting.create({
            data: {},
        });
        const product = await prismaClient.product.create({
            data: {},
        });
        if (layout && product) {
            await prismaClient.layoutSettingLinkProduct.createMany({
                data: {
                    layoutId: layout.id,
                    productId: product.id,
                    order: 1,
                },
            });
            const { count } =
                await prismaClient.layoutSettingLinkProduct.deleteMany({
                    where: {
                        layoutId: layout.id,
                    },
                });
            console.log(count);
        }
    I don’t know what I need to solve the problem, and I don’t know why there’s no error in the sample code... Is this a bug? Or is it my fault?
    r
    • 2
    • 5
  • c

    Casey Chow

    10/01/2021, 6:48 PM
    So here’s an interesting one: I noticed that our test runtimes doubled since adding Prisma (we have about 70 tables) and did a profile and found that importing prisma accounted for more than half the test runtime…any suggestions on improving test runtime?
  • р

    Роман Адигезалов

    10/02/2021, 7:00 AM
    Can you please tell me how to update the many-to-many relationship correctly? That is, the user has a specific array of roles. Suppose a role has been added or removed to a user during the upgrade. Should this be handled by separate requests? it is impossible to do this directly in the prisma.user.update request?
    r
    • 2
    • 1
  • u

    ut dev

    10/02/2021, 9:40 AM
    Hi 👋 , is it ok if I ask help on the general channel?
  • u

    ut dev

    10/02/2021, 9:42 AM
    I went through following tutorial and I currently get this error in my apollo after running a query:
    Copy code
    "message": "\nInvalid `prisma.link.findMany()` invocation:\n\n{\n  take: null\n        ~~~~\n}\n\n
    Argument take must not be null. Please use undefined instead.\n\n",
    I think it refers to this line in my graphql/resolvers.ts file
    Copy code
    export const resolvers = {
        Query: {
            links: (_parent, _args, ctx) => {
                return ctx.prisma.link.findMany()
            },
        },
    }
    ✅ 1
  • u

    ut dev

    10/02/2021, 10:22 AM
    Ah Nevermind I had to set the linksFirst variable in the apollo ui, now it works 🙂
    💯 1
  • m

    Max Hodges

    10/02/2021, 10:28 AM
    hi how dO I bulk insert into a prisma table? I tried
    Copy code
    INSERT INTO 'blackship$prod'.'WarehouseLocations' (name)
    VALUES 
    ('01-00-0-0'
    '01-00-0-1', etc.)
    but fails because
    null value in column "id" violates not-null constraint
    I see the id column is varchar, not an auto-number, so . . . what’s the method? do I gotta use javascript for this? 😞
    r
    • 2
    • 1
  • c

    Chris V

    10/02/2021, 10:34 AM
    Edit: I got it working. I was using AWS CodePipeline to deploy which included a CodeBuild step. The build step was using
    yarn
    for installing and building, whereas Elastic Beanstalk installs with
    npm
    . I updated the CodeBuild step to also use
    npm
    and things seem to be working 🤞 Still interesting to note that Prisma v2 worked fine the whole time. I'm having trouble deploying Prisma to Elastic Beanstalk - I am able to deploy Prisma at version 2, but not at version 3. When using
    prisma
    and
    @prisma/client
    at version 3, the Elastic Beanstalk
    npm --production install
    command fails but with no obvious error message - I will leave the full logs as a reply to this message. Any ideas what might cause this? As I say, if I downgrade to version 2 then the deployment works fine. I have also tried running
    npm --production install
    locally with the same version of Node used in the EB build, and it also works fine.
    r
    • 2
    • 5
  • o

    oliver

    10/02/2021, 11:27 AM
    Hi! We are currently developing a backend in Apollo+GraphQL+Prisma+Typescript with a Postgres DB. We are now looking for a way to deploy it to AWS, but we dont know what best practice is. From what we understand, prisma is too large to fit in AWS Lambda. Does anyone have experience or tips to share on how to get such a backend into production on AWS? Thanks! 🙂
    m
    c
    • 3
    • 10
  • m

    Martin Klasson

    10/02/2021, 5:40 PM
    Hi everyone. This is probably an easy query to do. Should be a common one, but my mind is not getting along at all with the next syntax with prisma.
    await prisma.discLibrary.findMany({????})
    I want to get all rows in discLibrary. but I also want the row from corresponding row in "DiscManufacturer"-model. How come it feels like it is tough? When it should be easyl The documentation does not help me out ;/
  • m

    Martin Klasson

    10/02/2021, 5:41 PM
    I can get the discManufacturerId easily.. but I want the corresponding row.
  • m

    Martin Klasson

    10/02/2021, 5:46 PM
    Found it out!!
    💯 1
  • d

    Danny

    10/02/2021, 8:23 PM
    Hey all... I'm having issues with seeding data with Prisma and TypeScript in a project that uses ESM modules (for HMR with SvelteKit/Vite). My seed script in package.json is
    ts-node prisma/seed.ts
    as recommended in the guide (currently seed.ts just has some console.logs for testing) and I have all the necessary dev dependencies installed. When I run
    prisma db seed
    I get the following:
    Copy code
    Environment variables loaded from .env
    Running seed command `ts-node ./prisma/seed.ts` ...
    
    An error occured while running the seed command:
    Error: Command failed with ENOENT: ts-node ./prisma/seed.ts
    spawn ts-node ENOENT
    Trying to run the script manually with ts-node with
    npx ts-node ./prisma/seed.ts
    I get the following:
    Copy code
    TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /workspace/prisma/seed.ts
        at new NodeError (node:internal/errors:371:5)
        at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)
        at Loader.getFormat (node:internal/modules/esm/loader:105:42)
        at Loader.getModuleJob (node:internal/modules/esm/loader:243:31)
        at async Loader.import (node:internal/modules/esm/loader:177:17)
        at async Object.loadESM (node:internal/process/esm_loader:68:5)
        at async handleMainPromise (node:internal/modules/run_main:63:12) {
      code: 'ERR_UNKNOWN_FILE_EXTENSION'
    }
    Has anybody run into this and know what's the best way to handle this from Prisma's end and found an elegant solution? This seems related to a big mess with ts-node when it comes to ESM support, ([1], [2], etc.) and the only way I've been able to get seed.ts to execute has been to remove
    type: "module"
    from my package.json. ts-node's docs recommend using an experimental Node.js API for using ts-node as a loader, but that's literally scheduled to break soon with node 16.10 and likely again in the future. I was also hopeful module type overrides would help, but it doesn't seem to do anything for executing seed.ts without these errors. My current workaround is to compile seed.ts with tsc, execute it with node, then clean up the js file. Since the prisma.seed command only takes one command and isn't bash-like, I create a package.json script with
    tsc prisma/seed.ts && node prisma/seed.js && rm prisma/seed.js
    and then make that my prisma.seed script
    "seed": "npm run seed-db"
    . This seems kind of clunky and I don't like that I have to write and clean up a transient file.
    r
    • 2
    • 1
  • u

    user

    10/02/2021, 10:50 PM
    What's new in Prisma? (Q3/21) Learn about everything that has happened in the Prisma ecosystem and community from July to September 2021.
  • f

    Faisal Sayed

    10/03/2021, 12:48 PM
    hey guys, i am unable to deploy my nextjs + prisma project to vercel. I'm constantly getting this error in my vercel console whenever I'm trying to fetch the nextauth's session:
    Copy code
    2021-10-03T12:47:13.217Z	1e02a299-de4d-4526-9a0c-6238a389ee61	ERROR	ReferenceError: prisma is not defined
        at Object.5324 (/var/task/.next/server/pages/api/auth/[...nextauth].js:23:10)
        at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:43)
        at Module.1529 (/var/task/.next/server/pages/api/auth/[...nextauth].js:51:14)
        at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:43)
        at __webpack_exec__ (/var/task/.next/server/pages/api/auth/[...nextauth].js:91:39)
        at /var/task/.next/server/pages/api/auth/[...nextauth].js:92:28
        at Object.<anonymous> (/var/task/.next/server/pages/api/auth/[...nextauth].js:95:3)
        at Module._compile (internal/modules/cjs/loader.js:1072:14)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
        at Module.load (internal/modules/cjs/loader.js:937:32)
    RequestId: 1e02a299-de4d-4526-9a0c-6238a389ee61 Error: Runtime exited with error: exit status 1
    Runtime.ExitError
    • 1
    • 4
  • m

    MichaelHindley

    10/03/2021, 7:05 PM
    When I init Prisma from the projects root, prisma seems to completely ignore the top-level
    prisma
    folder and tries to take both the
    schema.prisma/.env
    files from the deeply nested assets bundles from the infrastructure deployment outputs. Which does not even exist in those locations! Prisma is trying to load this path, which does not exist:
    /Users/hindley/Documents/project/aws/cdk.out/asset.352d16b78797811d23876d149c74340d4b5ae90245ec70aee0bc6d643d46fd1d/prisma/.env
    There is however a directory that looks somewhat like that but not quite:
    /Users/hindley/Documents/project/aws/cdk.out/asset.352d16b78797811d23876d149c74340d4b5ae90245ec70aee0bc6d643d46fd1d/node_modules/.prisma/
    I don’t even know how it’s finding the paths, not only that, the prisma determined location is missing the files it’s trying to load. The
    aws
    folder is excluded from tsconfig, is built separately and it’s also it’s own package with it’s own dependencies. There is nothing imported from there from the root-level entrypoint, this is triggered by simply importing the prisma client from any root-level file. I found this out by setting a breakpoint in https://github.com/prisma/prisma/blob/ba74c81fdbc9e6405946fdc6f9d42d103d008dc2/packages/client/src/runtime/getPrismaClient.ts#L300. envPath.schemaEnvPath is pointing to the alphabetically sorted most recent asset build. I suspect prisma is doing some deep tree traversal to find schema.prisma/.env files instead of checking things in the order that docs link below state. This is not consistent with the docs at https://www.prisma.io/docs/guides/development-environment/environment-variables#env-file-locations. It should load the
    prisma/.env
    files and though not specific, I would understand that the
    prisma/schema.prisma
    file should be used too, and not the first one encountered in deeply nested directories. Here is a basic repo: https://github.com/MichaelHindley/prisma-env-dbg
    r
    • 2
    • 5
  • u

    user

    10/04/2021, 7:54 AM
    Building a GraphQL schema using Nexus, Prisma and Nextjs

    https://www.youtube.com/watch?v=xub4lML2w18▾

    In this video, you'll learn how to add support for Pagination on the Server using Nexus and how to send a paginated query using Apollo Client Timestamps: 00:00 - 01:26 - Flaws of our GraphQL setup 01:26 - 6:53 - Code-first GraphQL APIs using Nexus Useful links: • Nexus makeSchema https://nexusjs.org/docs/api/make-schema • https://nexusjs.org/docs • GitHub repo: https://github.com/m-abdelwahab/awesome-links • Part 2 blog post: https://prisma.io/blog/fullstack-nextjs-graphql-prisma-2-fwpc6ds155 • Part 1 blog post: https://prisma.io/blog/fullstack-nextjs-graphql-prisma-oklidw1rhw 👉 Previous video: GraphQL Pagination using Apollo Client and on the Server -

    https://www.youtube.com/watch?v=NaxQXClnYSE&amp;list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&amp;index=18&amp;pp=sAQB▾

    👉 Check out the full playlist: https://www.youtube.com/playlist?list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk
  • d

    Donte

    10/04/2021, 8:58 AM
    Hello, from Prisma 1 it came with types built in like for example, it would generate types for a resetTokenExpiry field from the schema and show different types related like if it’s greater or equal to. But in Prisma 2 , I don’t see anything like tht. I’m trying to create a reset password function and having trouble getting the resetTokenExpiry . I did save it in my user object.
    Copy code
    Const {user} = ctx.Prisma.user.findMany({
     where:{
      resetToken: args.resetToken,
      resetTokenExpiry:???
     }
    })
    Is there another way to check for resetTokenExpiry? Thanks 😊
    r
    • 2
    • 1
  • m

    Moh

    10/04/2021, 9:32 AM
    Hey guys, need some help writing a query in one transaction. I could create this in 2 separate transactions, but can't use the $transaction API as I need the ID of the first query, so trying to figure out how its done in one. See below for a high level example, where treatment_city is a joiner table for the two entities, city and treatment - when I insert a treatment, I want to insert the treatment ID and one other field into the joiner table along with the cityIds passed through to the API
    Copy code
    await prisma.treatment.create({
    	data: {
    		name: "Treatment A",
    		clinic: { connect: { id: "SOME ID" }},
    		metadata: { create: { infos: "JSON" }},
    		treatment_city: {
    			createMany: {
    				data: cityIds.map(cityId => ({
    					city_id: cityId,
    					metadata_id: <Id from above>, (??)
    					treatment_id: <id of created treatment>, (??)
    				}))
    			}
    		}
    	}
    })
    d
    • 2
    • 9
  • f

    Francesco Bruno

    10/04/2021, 9:34 AM
    Hi there! I cannot get model typings and autocomplete to work on VS Code, i ran
    prisma generate
    and can use the prisma client, typing
    <http://prisma.XXX|prisma.XXX>
    suggests my model names correctly, however
    prisma.MODEL
    contains no typings. Any idea on how i could troubleshoot this?
    r
    • 2
    • 6
  • j

    Jonathan

    10/04/2021, 9:49 AM
    Hey, When dealing with n+1 problem-like environments (like graphql), are there any use cases where using include is beneficial over findUnique + fluent api? They both apparently result in the same number of queries, but the fluent api is more decoupled
    r
    • 2
    • 2
  • d

    do4gr

    10/04/2021, 10:48 AM
    We just spelled out a proposal for a round of enhanced index capabilities for the Prisma Schema language. We're happy to listen to feedback if you want to have a look before we start implementing. You can chime in on Github. https://github.com/prisma/prisma/issues/9577
  • p

    Phil Bookst

    10/04/2021, 10:49 AM
    Schema
    Copy code
    model Profile {
      id              String?     @unique
      username        String      @id
      profile_pic_url String?
      follower        Int?
      following       Int?
      images          Image[]
    
      @@map("profile")
    }
    
    model Location {
      id             String           @unique
      name           String           @id
      images         Image[]
    
      @@map("location")
    }
    
    model Hashtag {
      id            String?         @unique
      name          String          @id
      images        Image[]
      
      @@map("hashtag")
    }
    
    model Image {
      id              String           @id
      thumbnail       String
      shortcode       String           @unique
      like_count      Int
      comment_count   Int
    
      profile         Profile?         @relation(fields: [profileUsername], references: [username])
      profileUsername String?
      hashtag         Hashtag?         @relation(fields: [hashtagName], references: [name])
      hashtagName     String?
      location        Location?        @relation(fields: [locationId], references: [id])
      locationId      String?
    
      // Is this ok?
      @@index([id, profileUsername])
      @@index([id, hashtagName])
      @@index([id, locationId])
      // 
      @@map("image")
    }
    Hey guys, quick question - is it ok to set indexes on my relations? I've experienced slow reads but since I added the indexes above the speed has increased a lot! Is this safe to do or will it cause problems in the future when the tables get bigger?
    r
    j
    • 3
    • 16
  • u

    user

    10/04/2021, 11:41 AM
    Prisma Enterprise - The Evolution of Data Application Platforms with Pete Hunt + Q&A

    https://www.youtube.com/watch?v=QtxPTgxTZ-w▾

    In an interview, Pete Hunt & Søren Bramer Schmidt discuss how Twitter and Facebook move faster than the industry average while running a platform with millions of users. Pete Hunt is a Software Engineer @ Twitter Twitter: https://twitter.com/floydophone This talk was hosted at the Prisma Enterprise Event, where anyone interested in using Prisma in a team or at scale could learn new technical approaches. We invited engineering leaders from companies ranging from startups to larger corporations. 👉 Check all the recordings here: https://www.prisma.io/enterprise-event-2021
  • l

    Larry Mickie

    10/04/2021, 12:55 PM
    Hey everyone, quick question - is there a real-time/socket prisma client library for a postgres db?
    r
    • 2
    • 7
1...489490491...637Latest