the-road-to-graphql / fullstack-apollo-express-postgresql-boilerplate

💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
https://roadtoreact.com
MIT License
1.2k stars 265 forks source link

Errors: models.Message.findById is not a function #65

Closed tommyboylab closed 5 years ago

tommyboylab commented 5 years ago

Just want to start off by thanking you @rwieruch for your amazing tutorial. It's definitely the most comprehensive tutorial I've ever read on the subject.

I'm running into a problem with my server after finishing up the Authorization section of the Tutorial. I'm unable to run the query in the following section GraphQL Custom Scalars in Apollo Server and get the following error below.

I've tried to revisit the codebase here and copy it back page by page to see which (if any) would've caused the problem, but after cloning the whole repository again, I'm still getting the same issue. Any help helping me understand what's going on would be greatly appreciated.

This is the query in question:

query {
  message(id: "1") {
    id
    createdAt
    user {
      username
    }
  }
}

This is the error I'm getting and where:

{
  "errors": [
    {
      "message": "models.Message.findById is not a function",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "comment"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: models.Message.findById is not a function",
            "    at findById (/Users/user/Documents/Self/BFF/src/resolvers/message.js:11:35)",
tommyboylab commented 5 years ago

Solved my issue, for anyone new to the tutorial and using the latest dependencies (specifically Postgres V5) you'll need to replace findById() with findByPk().

Everything will work as expected.

platocrat commented 4 years ago

This seems to be an issue with Apollo Server or GraphQL and using Postgres as the database

MissyM2 commented 2 years ago

Thank you @tommyboylab and thank you @rwieruch. This tutorial as well as all your material is EXCELLENT.