users and posts
This commit is contained in:
parent
eb8ec371c7
commit
1a1830572d
1 changed files with 52 additions and 3 deletions
|
|
@ -1,11 +1,60 @@
|
||||||
import SchemaBuilder from "@pothos/core";
|
import SchemaBuilder from "@pothos/core";
|
||||||
|
import PrismaPlugin, {
|
||||||
|
type PrismaTypesFromClient,
|
||||||
|
} from "@pothos/plugin-prisma";
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
const builder = new SchemaBuilder({});
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
const builder = new SchemaBuilder<{
|
||||||
|
PrismaTypes: PrismaTypesFromClient<typeof prisma>;
|
||||||
|
}>({
|
||||||
|
plugins: [PrismaPlugin],
|
||||||
|
prisma: {
|
||||||
|
client: prisma,
|
||||||
|
// defaults to false, uses /// comments from prisma schema as descriptions
|
||||||
|
// for object types, relations and exposed fields.
|
||||||
|
// descriptions can be omitted by setting description to false
|
||||||
|
exposeDescriptions: false,
|
||||||
|
// use where clause from prismaRelatedConnection for totalCount (defaults to true)
|
||||||
|
filterConnectionTotalCount: true,
|
||||||
|
// warn when not using a query parameter correctly
|
||||||
|
onUnusedQuery: process.env.NODE_ENV === "production" ? null : "warn",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const User = builder.prismaObject("User", {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID("id"),
|
||||||
|
email: t.exposeString("email"),
|
||||||
|
name: t.exposeString("name"),
|
||||||
|
posts: t.relation("posts"),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const Post = builder.prismaObject("Post", {
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeID("id"),
|
||||||
|
title: t.exposeString("title"),
|
||||||
|
content: t.exposeString("content"),
|
||||||
|
published: t.exposeBoolean("published"),
|
||||||
|
author: t.relation("author"),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
builder.queryType({
|
builder.queryType({
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
hello: t.string({
|
users: t.prismaField({
|
||||||
resolve: () => "world",
|
type: [User],
|
||||||
|
resolve: async () => {
|
||||||
|
return await prisma.user.findMany();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
posts: t.prismaField({
|
||||||
|
type: [Post],
|
||||||
|
resolve: async () => {
|
||||||
|
return await prisma.post.findMany();
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue