I was following a tutorial for a full stack web application with NextJS GraphQLNexus and Prisma along with Apollo server to handle the api.
Everything was working until I changed an enum type somewhere and now the linter is yelling at me for types that seem to be the same but are nonetheless diffrent.
The exact error is super wordy but here it is in it's entirety
Type 'PrismaPromise<Tickets[]>' is not assignable to type 'MaybePromise<{ active?: boolean; broken_item?: string; creator?: number; id?: number; issue_desc?: string; loc?: string; prio?: "Low" | "Medium" | "High" | "Critical" | "Very Low"; }[]>'.
Type 'PrismaPromise<Tickets[]>' is not assignable to type 'PromiseLike<{ active?: boolean; broken_item?: string; creator?: number; id?: number; issue_desc?: string; loc?: string; prio?: "Low" | "Medium" | "High" | "Critical" | "Very Low"; }[]>'.
Types of property 'then' are incompatible.
Type '<TResult1 = Tickets[], TResult2 = never>(onfulfilled?: (value: Tickets[]) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => Promise<...>' is not assignable to type '<TResult1 = { active?: boolean; broken_item?: string; creator?: number; id?: number; issue_desc?: string; loc?: string; prio?: "Low" | "Medium" | "High" | "Critical" | "Very Low"; }[], TResult2 = never>(onfulfilled?: (value: { active?: boolean; ... 5 more ...; prio?: "Low" | ... 3 more ... | "Very Low"; }[]) => TRes...'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type 'Tickets[]' is not assignable to type '{ active?: boolean; broken_item?: string; creator?: number; id?: number; issue_desc?: string; loc?: string; prio?: "Low" | "Medium" | "High" | "Critical" | "Very Low"; }[]'.
Type 'Tickets' is not assignable to type '{ active?: boolean; broken_item?: string; creator?: number; id?: number; issue_desc?: string; loc?: string; prio?: "Low" | "Medium" | "High" | "Critical" | "Very Low"; }'.
Types of property 'prio' are incompatible.
Type 'prio_level' is not assignable to type '"Low" | "Medium" | "High" | "Critical" | "Very Low"'.
Type '"Very_Low"' is not assignable to type '"Low" | "Medium" | "High" | "Critical" | "Very Low"'. Did you mean '"Very Low"'?ts(2322)
definitionBlocks.d.ts(158, 5): The expected type comes from property 'resolve' which is declared here on type 'NexusOutputFieldConfig<"Query", "tickets">'
Here is the resolver it errors on: in graphql/types/Ticket.ts
export const TicketQuery = extendType({
type: 'Query',
definition(t) {
t.list.field('tickets', {
type: Ticket,
resolve(_parent, _args, ctx) {
return ctx.prisma.tickets.findMany()
},
})
},
})
The query is called tickets because I was following tutorial but it seems to be in the schema.graphql:
type Query {
tickets: [Ticket]!
}
Here is everywhere I could find that the Enum is defined:
In graphql/types/Ticket.ts:
const PrioEnum = enumType({
name: 'PrioEnum',
members: {
Very_Low: 'Very_Low',
Low: 'Low',
Medium: 'Medium',
High: 'High',
Critical: 'Critical',
},
})
In graphql/schema.graphql:
enum PrioEnum {
Very_Low
Low
Medium
High
Critical
}
Finally in prisma/schema.prisma :
enum prio_level {
Very_Low @map("Very_Low")
Low
Medium
High
Critical
}
Originally I thought it was just not recognizing updates to the enum because Very_Low used to be mapped to @map("Very Low") but I made the current change and the did npx prisma db push
which warned me that I was changing the enum value for Very_Low in the database (I hadn't written anything to it yet) and then confirmed the change with no further warnings or errors.
I think maybe swapping all the enums to "Very Low" might fix it but I shouldn't have to.
I'm not exactly sure what it was but making sure all the schema was named correct everywhere relaunching VS Code and rerunning the server fixed it. I think it was the linter getting confused on old version of the schema that were never getting pushed to it.