Failed to validate the query: `Field does not exist on enclosing type.`

I’m creating a simple project where I plan on using the Google Books API, and have been setting up my app following the Redwood Getting Started docs. I’m using Typescript, and I’ve created this model:

model Book {
  id    Int     @id @default(autoincrement())
  title String
  author  String
  createdAt DateTime @default(now())
}

I ran yarn rw prisma migrate dev and all went well – I can see the correct table in my PG database through Postico. If I run yarn rw prisma studio, I can also see the table there.

So then I ran yarn rw g scaffold book to generate my CRUD functions and cells. The problem is that I’m getting an error when trying to run any CRUD functions. For example, here is the error I get when trying to view all my books from the /books route:

Invalid `db.book.findMany()` invocation in
/Users/redactedusername/Desktop/Projects/Portfolio/books-api/api/src/services/books/books.ts:6:18

import { db } from 'src/lib/db'
export const books = () => {
return db.book.findMany(
Failed to validate the query: `Field does not exist on enclosing type.` at `Query.findManyBook`

I went into the the DB and manually added a book to see if it might be able to run the query then, but no luck. Attempting to create a book yields a similar error.

My Cell for FindBooks looks like this:

export const QUERY = gql`
  query FindBooks {
    books {
      id
      title
      author
      createdAt
    }
  }
`

I’m also getting an error in VS code on ‘books’ in the above query saying this:
Cannot query field "books" on type "Query"

I’m not sure where this is coming from? I have this in my /src/graphql:

type Query {
    books: [Book!]! @requireAuth
    book(id: Int!): Book @requireAuth
  }

So I don’t understand where this is coming from. I think it has to do with Typescript since I did this last night with just JS and it all worked, but I’m scratching my head on how to fix it.

Hi @aemann2 we recently fixed an issue where types did not generate after certain scaffolding.

Could you try:

  • stop your dev server
  • yarn rw g types
  • yarn rw dev

And see if that helps resolve the issue?

@dthyresson, that worked! Thank you.

1 Like

Great to hear! That fix has been merged and will be in the next release 0.45.

1 Like