Prisma throws an error "TypeError: cannot read property findmany of undefined"

I wanted to make a chat app to practice working with graphql and node, for database I used prisma. I was doing everything like in this tutorial.

https://www.howtographql.com/graphql-js/0-introduction/

I just changed variable names.

so I have this code

const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()


const resolvers = {
  Query: {
    history: async (parent, args, context) => {
      return context.prisma.Messages.findMany()
    },
  },
  Mutation: {
    post: (parent, args, context) => {
      const newMessage = context.prisma.Messages.create({
        data: {
          username: args.username,
          message: args.message,
        },
      })
      return newMessage
    },
  },
}

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: {
    prisma,
  }
})
server.start(() => console.log(`Server is running on http://localhost:4000`))

as my index.js

this is my schema.prisma

  provider = "sqlite"
  url      = "file:./dev.db"
}


generator client {
  provider = "prisma-client-js"
}


model Message {
  id       Int      @id @default(autoincrement())
  sendedAt DateTime @default(now())
  message  String
  username String
}

script.js

const { PrismaClient } = require("@prisma/client")


const prisma = new PrismaClient()


async function main() {
  const newMessage = await prisma.Messages.create({
    data: {
      message: 'Fullstack tutorial for GraphQL',
      username: 'www.howtographql.com',
    },
  })
  const allMessages = await prisma.Messages.findMany()
  console.log(allMessages)
}


main()
  .catch(e => {
    throw e
  })
  // 5
  .finally(async () => {
    await prisma.disconnect()
  })

and schema.graphql

type Query {
  history: [Message!]!
}

type Mutation {
  post(username: String!, message: String!): Message!
}

type Message {
  id: ID!
  message: String!
  username: String!
}

and that is what i got in my playground

  "data": null,
  "errors": [
    {
      "message": "Cannot read property 'findMany' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "history"
      ]
    }
  ]
}

please help

31 thoughts on “Prisma throws an error "TypeError: cannot read property findmany of undefined"”

  1. I am doing exactly what you are doing (from the same tutorial) and I am getting the same error. I do see your response about the lowercase, could you please explain a bit more about what you changed and how it made a difference?

    Reply
  2. Hey There. I discovered your weblog the use of msn. This is an extremely smartly written article.
    I will be sure to bookmark it and return to read more
    of your useful info. Thank you for the post. I will definitely
    return.

    Here is my web blog :: riyapola.com

    Reply
  3. Your style is unique compared to other folks I’ve read stuff from.
    Thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

    Feel free to visit my website – download live22 mobile service android (918kiss-m.com)

    Reply
  4. Oh my goodness! Awesome article dude! Thank you, However I
    am having problems with your RSS. I don’t know the
    reason why I am unable to subscribe to it. Is there anybody else getting similar RSS problems?
    Anybody who knows the solution will you kindly
    respond? Thanks!!

    Feel free to visit my blog; 918kiss 2 original

    Reply
  5. Pretty nice post. I just stumbled upon your blog and wished to say that I have
    really enjoyed surfing around your blog posts. After all I
    will be subscribing to your feed and I hope you write again soon!

    My webpage … id Test mega888 – 918kiss-m.com

    Reply
  6. I truly wanted to jot down a simple comment so as to thank you for
    some of the pleasant steps you are giving out at this website.
    My incredibly long internet look up has at the end been paid with
    useful tips to share with my best friends. I would express that we site visitors are definitely lucky to be in a good community with so many outstanding
    people with helpful guidelines. I feel rather happy to have seen your web site and look forward to
    so many more cool minutes reading here. Thank you again for
    all the details.

    Here is my blog … laptoplifestyleads.com

    Reply
  7. I have been exploring for a little bit for any high quality
    articles or weblog posts in this kind of space .
    Exploring in Yahoo I ultimately stumbled upon this web site.
    Studying this information So i’m satisfied to express that I have
    an incredibly just right uncanny feeling I found out exactly what I needed.
    I so much indubitably will make sure to do not overlook this site and give it a look regularly.

    Also visit my web-site; equipifieds.com

    Reply
  8. Undeniably believe that which you said. Your favorite reason appeared to be on the net the simplest thing to be aware of.
    I say to you, I definitely get annoyed while people consider worries that
    they plainly don’t know about. You managed to hit the nail upon the top as well as
    defined out the whole thing without having side-effects
    , people can take a signal. Will probably be back
    to get more. Thanks

    Also visit my webpage: kannikar.com

    Reply
  9. Hello superb blog! Does running a blog like this take
    a massive amount work? I’ve absolutely no knowledge of computer programming
    however I was hoping to start my own blog soon. Anyway, if you have any recommendations or techniques for
    new blog owners please share. I know this is off topic but I simply
    wanted to ask. Thanks!

    Here is my website: http://www.aniene.net

    Reply
  10. I have been browsing online greater than 3 hours lately, yet I never found any attention-grabbing article like yours.
    It is pretty value sufficient for me. Personally,
    if all webmasters and bloggers made good content material as you did, the
    web will likely be a lot more helpful than ever before.

    Here is my web-site … payfirstsolutions.com

    Reply

Leave a Comment