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

    Nima Shoghi

    08/02/2021, 4:21 PM
    Hi all. I had a quick question about the referential actions preview feature. The docs mention that referential actions do not work w/ implicit many to many relations. Does this mean that we need to update our schema to use explicit many-to-many relations, even if we are using the default referential actions for those models?
    r
    • 2
    • 1
  • p

    Pavel Vorontsov

    08/02/2021, 8:17 PM
    Hey Guys. I'm new here. I'm trying to start yoga server
    Copy code
    const typeDefs = `
      type Query {
        hello(name: String): String!
      }
    `
    
    const resolvers = {
      Query: {
        hello: (_, { name }) => `Hello ${name || 'World'}`,
      },
    }
    
    const server = new GraphQLServer({ typeDefs, resolvers })
    but I get following { "error": "Unexpected token < in JSON at position 0" } Any help? Thanks
    r
    • 2
    • 6
  • j

    Jay Bell

    08/02/2021, 8:32 PM
    Hey everyone, for some reason. CI when I have postgres running and run
    prisma db push
    I get
    Copy code
    {
      "timestamp": "2021-08-02T17:27:04.778303482+00:00",
      "level": "ERROR",
      "fields": {
        "is_panic": false,
        "error_code": "P1003",
        "message": "Database `<db name>.public` does not exist on the database server at `localhost:5432`."
      },
      "target": "migration_engine::logger"
    }
    Shouldn't it create the db if it doesn't already exist? It does on another step in CI (and locally) which is weird... the step that does not work is using docker executor and the one that does work is using ubuntu machine executor (both on circleci) Anyone have any ideas here? I am at a loss. This is a fresh postgres instance (using
    docker-compose up
    ) so no DBs (Cross posted as I didn't notice general had 58x the members as the other channel!)
  • u

    user

    08/03/2021, 5:07 AM
    Connect Dev Africa #2 + raffle

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

    Join our second edition of Connect Dev Africa Meetup on the 11th of August, 5 PM CEST. 🌍 This is a community for connecting developers and developer communities within Africa - showcasing awesome engineers and products. 🤩 We have two amazing speakers lined up: ◭ Segun Adebayo (thesegunadebayo) - Building Accessible Design Systems with React ◭ Anthony Kiplimo (AnthonyLimo) - Elarian - A Tale of Communication & Data
  • o

    Oluwasetemi Ojo

    08/03/2021, 9:34 AM
    I am having issues with prisma 2.26.0 mongodb Write Query is not working when I moved my db to aws ec2 for hosting. Anyone has an idea of what is happening and how I can fix it .
  • o

    Oluwasetemi Ojo

    08/03/2021, 9:46 AM
    DATABASE_URL=“mongodb://root:prisma@localhost:27017/groovy_db?authSource=admin&amp;retryWrites=true&amp;w=majority”
    l
    • 2
    • 3
  • d

    Daan Helsloot

    08/03/2021, 10:54 AM
    Did the way Floats in schema.prisma were interpreted change some where between 2.8 -> 2.28? In my old database i see Numeric (65, 30) whereas with the new migrate tool these are turned into double precision. Because of this my migration for production environment is telling me my entire production database would be wiped even after running npx prisma migrate resolve --applied
    r
    • 2
    • 4
  • v

    Vladi Stevanovic

    08/03/2021, 10:58 AM
    ❓ Have you ever watched a YouTube video on mute and the captions sometimes didn't make sense? "_style guides for the dev community_" can easily be transcribed by YouTube as '_style guys for the deaf community_'. 😅 🙌 Starting today, Prisma will sponsor free, professional closed captions for ANY YouTube video in English, relevant to our community. E.g. covering content about Node.js, TypeScript & type safety, databases and Prisma. While you can (and should) always enable auto-captioning in YouTube, we want to offer you the option of having captions that are 99% accurate, with punctuation and no misspelled technical terms. 👉 Learn how to get your free captions at: https://pris.ly/closedcaptions
    👏 3
    💓 3
  • g

    Georg Wagner

    08/03/2021, 12:35 PM
    Hi @all, Prisma should be transactional on nested creates right? But unfortunately it isn't ☹️. In the following mutation the connection of the inner object "Order" throws an Authorization error. BUT: A new product is still created. It this correct behavior? Is it possible to abort the creation of the product? mutation createProductMutation { createProduct(data: { name: "test36", orders:{ create: { customer: { connect: { id: "81c9cb84-6b9e-4b61-b067-33d83d813043" } } } } }) { name } }
    r
    • 2
    • 3
  • p

    Peter Kellner

    08/03/2021, 7:34 PM
    I'm kind of baffled when I see in the docs a description of parameters like this:
    XOR<UserSelect,null>.
    That syntax means nothing to me. Is there some page that explains this syntax? I get from the example that somehow, it relates to where: {id: 1}... but I just don't see the connection and normally, I'm not the dumbest pencil in the box (so I had thought)
    c
    • 2
    • 10
  • c

    Casey Graff

    08/03/2021, 11:29 PM
    Is there a way to pass additional non-unique conditions to a
    where
    block in a Prisma
    *Unique
    operation? In our case, we have a
    tenantId
    on a model and would like users to only be able to read/edit/delete objects with a
    tenantId
    that matches the tenant they belong to. Ideally, we could just pass the
    tenantId
    along with a unique field (like
    id
    ) e.g.
    prisma.model.findUnique({where: {id: <id>, tenantId: <tenantId>}})
    . For finds, this isn't really an issue because you can always check the
    tenantId
    after you fetch the object, but for mutations, it currently requires either, fetching the object first, verifying it's
    tenantId
    and then performing the mutation, or using a Prisma
    updateMany
    or
    deleteMany
    and passing both the
    id
    and
    tenantId
    into the
    where
    block of the
    *Many
    operation. Using a
    *Many
    operation concerns me a bit because if the
    id
    is ever
    undefined
    the operation would then apply to significantly more objects than intended; whereas a
    *Unique
    operation would just fail. I'm going to guess that Prisma doesn't support this as they use the
    *Many
    trick in the soft-deletion middleware docs (here). One workaround we've found is that you can add a
    @@unique
    constraint to
    id
    +
    tenantId
    (e.g.
    @@unique([id, tenantId])
    ). This then allows you to perform any
    *Unique
    operation against an
    id
    +
    tenantId
    pair. Is this the best way to do this as we are now introducing an additional index? Alternatively, you could make it a composite id with
    @@id([id, tenantId])
    , but then
    id
    field would no longer be required to be unique unless you additionally added
    @unique
    to the
    id
    field. Has anyone used any of these method and found something they recommend?
    r
    • 2
    • 3
  • z

    Zestian

    08/04/2021, 12:37 AM
    Hello, is there a way to insert initial database rows in my database by using an array of items in js? and automate it in migrations
    c
    • 2
    • 2
  • m

    Mateusz Żmijewski

    08/04/2021, 11:07 AM
    Hey, how can I create a new Entity and attach existing fields to it from relation? For example, I want to create a Chat and set the user field to an existing user. I tried using connect through user's id but it didn't work.
    r
    • 2
    • 9
  • r

    Rahul Agrawal

    08/04/2021, 11:20 AM
    i want to use data source provider to be dynamic in
    schema.prisma
    based on env variable But typescript complains that it is not allowed Is there any way to achieve this?
    r
    • 2
    • 8
  • g

    Georg Wagner

    08/04/2021, 12:10 PM
    Hi dear people, for approximately 30-40 hours I am looking for a way to realize some content-dependent authorization for mutations in a generic way. say, given are 3 Models Product -> Order -> User. and a nested mutation called createProduct. createProduct should authorize if user "James" is executing the mutation and the user record in the mutation argument holds his userID. It should not authorize, if there is a different userId inside in the user record. This should not be realized only with specific code only for the createProduct mutation. Why? Because there are also mutations like createCategory which in the end contain createProduct as sub mutation: Category -> Product -> Order -> User I tried so many things. Not possible mit Graphql-Shield or prisma middleware, or own typegraphl-middleware. Also I tried it with Graphql-Directives and Visitors. But this does only work for Queries - not for mutations, because ArgumentObjects or InputTypeObjects do not have reesolvers on their own. Researched so much articles and looked in the code, but it seems there is no easy way for it. In the moment I believe, the only method would be some ugly use of Magic field names "MAGIC_user_id" and each mutation should check in its arguments array, whether that MAGIC_user_id exists and compare, whether it is the current logged in id (which can be read from my context) Does anybody understand my problem or experienced similar and has an idea how to solve it?
    r
    j
    • 3
    • 7
  • g

    Georg Wagner

    08/04/2021, 12:15 PM
    Thought also of creating an own scalar which checks, which userId is writing. But it seems that scalar logic don't hold context
  • u

    user

    08/04/2021, 2:24 PM
    GraphQL Nairobi Meetup + a raffle!

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

    Tune in for the first online edition of GraphQL Nairobi Meetup! Connect with the GraphQL enthusiasts worldwide, get inspired by the talks, join the Q&A session and win a copy of "Production Ready GraphQL" book by Marc-Andre Giroux in the raffle! The lineup: ◭ Joey Ng'ethe (@AfricanSinatra), Mahmoud Abdelwahab (@thisismahmoud_): "Building a GraphQL API with Prisma", ◭ Julian Mayorga (@_okjulian_): "Generating GraphQL Queries" During this meetup you will be able to win the "Production Ready GraphQL" book by Marc-Andre Giroux! Join our Meetup group: https://www.meetup.com/Nairobi-GraphQL-Meetup/ Learn more about Prisma: ◭ Website: https://www.prisma.io​​ ◭ Docs: https://www.prisma.io/docs​​ ◭ Quickstart: https://www.prisma.io/docs/getting-started/quickstart
  • i

    Ivan Lukianchuk

    08/04/2021, 8:03 PM
    I feel like something broke recently as I had code that made sense based on the docs and worked and weeks later (after prisma updates) I come back and it no longer works... Error: { data: { ticketId: 226, ~~~~~~~~ + ticket: { + create?: TicketCreateWithoutTemplateTicketIdInput | TicketUncheckedCreateWithoutTemplateTicketIdInput, + connectOrCreate?: TicketCreateOrConnectWithoutTemplateTicketIdInput, + connect?: TicketWhereUniqueInput + }, } } } Unknown arg
    ticketId
    in data.ticketId for type TemplateItemCreateInput. Did you mean
    ticket
    ? Argument ticket for data.ticket is missing.
    Copy code
    const creation = await prisma.templateItem.create({
                            data: {
                                ticketId: ticket.id
                            }
                        });
    And here is the simplified schema: model TemplateItem { id Int @id @default(autoincrement()) ticket Ticket @relation(fields: [ticketId], references: [id]) ticketId Int } model Ticket { id Int @id @default(autoincrement()) templateTicketId TemplateItem? } I've removed extra stuff that isn't important to simplify the code So if I've got a 1-1 relationship setup, why won't it let me pass in the ticketId? It sounds like it doesn't even understand that it's in the schema, yet it's clearly there and worked before. Am I missing something or did something change? I want to make a TemplateItem and reference the id of the existing Ticket.
  • k

    Kent C. Dodds

    08/04/2021, 9:00 PM
    Heya friends. I was surprised to find that this
    findUnique
    with an
    include
    resulted in two queries rather than one SQL query. Am I doing something wrong/misunderstanding something?
    Copy code
    const session = await prisma.session.findUnique({
      where: {id: sessionId},
      include: {user: true},
    })
    Results in:
    Copy code
    SELECT "public"."Session"."id", "public"."Session"."createdAt", "public"."Session"."userId", "public"."Session"."expirationDate" FROM "public"."Session" WHERE "public"."Session"."id" = $1 LIMIT $2 OFFSET $3
    
    SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."email", "public"."User"."firstName", "public"."User"."discordId", "public"."User"."convertKitId", "public"."User"."role", "public"."User"."team" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
    Is there a reason that can't be combined into a single query?
    👀 1
    r
    • 2
    • 1
  • h

    Halvor

    08/04/2021, 9:01 PM
    Is it possible in one query to generate a 8 bytes that is guaranteed to be unique? I would like to base it on the auto generated id, but no way to do that in a single prisma.create() is it?
  • k

    Kent C. Dodds

    08/04/2021, 9:13 PM
    So are you saying that if I change this to a
    findMany
    it'll be able to combine it into a single query?
  • k

    Kent C. Dodds

    08/04/2021, 9:15 PM
    If I do change it to
    findMany
    , then here's what I get:
    Copy code
    SELECT "public"."Session"."id", "public"."Session"."createdAt", "public"."Session"."userId", "public"."Session"."expirationDate" FROM "public"."Session" WHERE "public"."Session"."id" = $1 OFFSET $2
    
    SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."email", "public"."User"."firstName", "public"."User"."discordId", "public"."User"."convertKitId", "public"."User"."role", "public"."User"."team" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
    The only difference is the
    LIMIT
    🤷‍♂️
  • n

    nmw03

    08/04/2021, 9:16 PM
    hi everyone
  • n

    nmw03

    08/04/2021, 9:18 PM
    This is my model. I can't access
    feeds
    here.
  • n

    nmw03

    08/04/2021, 9:18 PM
    r
    • 2
    • 2
  • k

    Kent C. Dodds

    08/04/2021, 9:50 PM
    Did you
    npx prisma generate
    after changing the schema?
  • n

    nmw03

    08/04/2021, 9:58 PM
    yes
    🤷‍♂️ 1
  • n

    nmw03

    08/04/2021, 9:59 PM
    i looked at old messages, it seems I should run
    prisma save
    🤔
  • k

    Kent C. Dodds

    08/04/2021, 10:00 PM
    I've never heard of that command before. Maybe it's new?
  • n

    nmw03

    08/04/2021, 10:01 PM
    https://prisma.slack.com/archives/CA491RJH0/p1604270692488100?thread_ts=1604263207.487900&amp;cid=CA491RJH0
1...466467468...637Latest