split up files
This commit is contained in:
parent
5395e7f904
commit
be2e559602
5 changed files with 82 additions and 77 deletions
24
src/lib/pothos/builder.ts
Normal file
24
src/lib/pothos/builder.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { prisma } from '$lib/prisma';
|
||||||
|
import type { Context } from '$lib/yoga';
|
||||||
|
import SchemaBuilder from '@pothos/core';
|
||||||
|
import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma';
|
||||||
|
|
||||||
|
type ContextType = ReturnType<typeof Context>;
|
||||||
|
|
||||||
|
export const builder = new SchemaBuilder<{
|
||||||
|
Context: ContextType;
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -1,65 +1,3 @@
|
||||||
import { prisma } from '$lib/prisma';
|
import { builder } from './builder';
|
||||||
import { Context } from '$lib/yoga/context';
|
|
||||||
import SchemaBuilder from '@pothos/core';
|
|
||||||
import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma';
|
|
||||||
|
|
||||||
type ContextType = ReturnType<typeof Context>;
|
|
||||||
|
|
||||||
export const builder = new SchemaBuilder<{
|
|
||||||
Context: ContextType;
|
|
||||||
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({
|
|
||||||
fields: (t) => ({
|
|
||||||
version: t.string({
|
|
||||||
resolve: (parent, args, context) => context.config.app_version
|
|
||||||
}),
|
|
||||||
users: t.prismaField({
|
|
||||||
type: [User],
|
|
||||||
resolve: async () => {
|
|
||||||
return await prisma.user.findMany();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
posts: t.prismaField({
|
|
||||||
type: [Post],
|
|
||||||
resolve: async () => {
|
|
||||||
return await prisma.post.findMany();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
export const Schema = builder.toSchema();
|
export const Schema = builder.toSchema();
|
||||||
41
src/lib/pothos/schema.ts
Normal file
41
src/lib/pothos/schema.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { prisma } from '$lib/prisma';
|
||||||
|
import { builder } from './builder';
|
||||||
|
|
||||||
|
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({
|
||||||
|
fields: (t) => ({
|
||||||
|
version: t.string({
|
||||||
|
resolve: (parent, args, context) => context.config.app_version
|
||||||
|
}),
|
||||||
|
users: t.prismaField({
|
||||||
|
type: [User],
|
||||||
|
resolve: async () => {
|
||||||
|
return await prisma.user.findMany();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
posts: t.prismaField({
|
||||||
|
type: [Post],
|
||||||
|
resolve: async () => {
|
||||||
|
return await prisma.post.findMany();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
@ -1,14 +1,2 @@
|
||||||
import { yogaLogger } from '$lib/logger';
|
export * from './context';
|
||||||
import { Schema } from '$lib/pothos';
|
export * from './server';
|
||||||
import type { RequestEvent } from '@sveltejs/kit';
|
|
||||||
import { createYoga } from 'graphql-yoga';
|
|
||||||
import { Context } from './context';
|
|
||||||
|
|
||||||
export const Yoga = createYoga<RequestEvent>({
|
|
||||||
context: Context,
|
|
||||||
schema: Schema,
|
|
||||||
graphqlEndpoint: '/api/graphql',
|
|
||||||
// Let Yoga use sveltekit's Response object
|
|
||||||
fetchAPI: { Response },
|
|
||||||
logging: yogaLogger
|
|
||||||
});
|
|
||||||
14
src/lib/yoga/server.ts
Normal file
14
src/lib/yoga/server.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { yogaLogger } from '$lib/logger';
|
||||||
|
import { Schema } from '$lib/pothos';
|
||||||
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
import { createYoga } from 'graphql-yoga';
|
||||||
|
import { Context } from './context';
|
||||||
|
|
||||||
|
export const Yoga = createYoga<RequestEvent>({
|
||||||
|
context: Context,
|
||||||
|
schema: Schema,
|
||||||
|
graphqlEndpoint: '/api/graphql',
|
||||||
|
// Let Yoga use sveltekit's Response object
|
||||||
|
fetchAPI: { Response },
|
||||||
|
logging: yogaLogger
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue