0
I’m creating a graphql with nextjs using prisma, and pothos. I’ve defined the schema for my table:
schema.prisma:
model Course {
id Int @id @unique @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String
published Boolean
courseId String
cId String
Lessons Lesson[]
}
I’ve added this as my resolver/graphql types:
import { builder } from "../builder";
builder.prismaObject("Course", {
fields: (t) => ({
id: t.exposeID('id'),
title: t.exposeString('title'),
content: t.exposeString('content'),
courseId: t.exposeString('courseId'),
cId: t.exposeString('cId'),
Lesson: t.relation('Lessons'),
})
})
builder.queryField("courses", (t) =>
t.prismaField({
type: ['Course'],
resolve: (query, _parent, _args, _ctx, _info) => {
console.log('The query', query);
return prisma.course.findMany({ ...query })
}
})
)
builder:
import SchemaBuilder from "@pothos/core";
import PrismaPlugin from '@pothos/plugin-prisma';
import type PrismaTypes from '@pothos/plugin-prisma/generated';
import prisma from "../lib/prisma";
export const builder = new SchemaBuilder<{
PrismaTypes: PrismaTypes
}>({
plugins: [PrismaPlugin],
prisma: {
client: prisma,
}
})
builder.queryType({
fields: (t) => ({
ok: t.boolean({
resolve: () => true,
}),
}),
});
I have seeded the db, and I can run postgresql queries and return the all the data, however when I run the query on Yoga GraphiQL, I get an error:
"message": "Cannot return null for non-nullable field Lesson.catId.",
This postgresql query works on the db:
SELECT * FROM "Lesson" WHERE "category" = 'football';
I have set the cId: t.exposeString('cId', { nullable: true }),
and category: t.exposeString('category', { nullable: true }),
and data comes back but with both cId and category
are null. I have tried npx prisma generate
but that didn’t work, I have tried clearing the database and re-run the prisma push and prisma seed commands, but no difference. It is also good to note that all other data comes back, except for cId and Category. cId and Category were added after the fact, and then I had to drop all tables and re-run the db push and db seed commands to update the db. I don’t know if that has somehow something to do with this, but I am unsure how to debug any further.
Any help here would be greatly appreciated.