I'm having a GraphQL issue that popped up recently and I'm not sure where to go since I believe i'm following the GraphQL documentation correctly on querying.
I have the following model.
model Contract {
id Int @id @default(autoincrement())
userId Int?
vin String
make String
model String
year Int
ownersName String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ownersEmail String @default("")
User User? @relation(fields: [userId], references: [id])
Dealership Dealership @relation(fields: [dealershipId], references: [id])
notes Note[]
dealershipId Int
}
Here are the related types
type Contract {
id: Int!
vin: String!
make: String!
model: String!
year: Int!
ownersName: String!
User: User
userId: Int
createdAt: DateTime
updatedAt: DateTime
ownersEmail: String
}
type Query {
contractsByUser: [Contract]
}
and here is my query which i'm exporting from a cell
export const QUERY = gql`
query ContractByUser {
contractsByUser {
id
vin
make
model
year
ownersName
createdAt
}
}
I get the following error.
api | ERROR [2021-08-04 13:28:03.477 +0000] (apollo-graphql-server): GraphQL didEncounterErrors
api | errors: [
api | {
api | "message": "Cannot query field \"contractsByUser\" on type \"Query\".",
api | "locations": [
api | {
api | "line": 2,
api | "column": 3
api | }
api | ]
api | }
api | ]
api | INFO [2021-08-04 13:28:03.479 +0000] (apollo-graphql-server): GraphQL willSendResponse
api |
api | Error: Cannot query field "contractsByUser" on type "Query".
api |
api |
api | POST /graphql 400 21.533 ms - 1329
api |
api | GraphQLError: Cannot query field "contractsByUser" on type "Query".
This is definitely a validation error, but I'm not sure what i've missed or done incorrectly. I'm on the latest Version of Redwood and updated the breaking changes. Any help would be good. Maybe its not generating types correctly or.... any help would be appreciated.
I had redwood graphql function misconfigured and it wasn't importing the generated types.
Where I was:
Where I needed to be: