move to lib

This commit is contained in:
Benjamin Palko 2024-12-10 10:00:35 -05:00
parent b10cb37549
commit 7954843448
2 changed files with 24 additions and 23 deletions

22
src/lib/yoga/index.ts Normal file
View file

@ -0,0 +1,22 @@
import type { RequestEvent } from '@sveltejs/kit';
import { createSchema, createYoga } from 'graphql-yoga';
export const Yoga = createYoga<RequestEvent>({
schema: createSchema({
typeDefs: `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'SvelteKit - GraphQL Yoga'
}
}
}),
// Needed to be defined explicitly because our endpoint lives at a different path other than `/graphql`
graphqlEndpoint: '/api/graphql',
// Needed to let Yoga use sveltekit's Response object
fetchAPI: { Response }
});

View file

@ -1,24 +1,3 @@
import { createSchema, createYoga } from 'graphql-yoga';
import type { RequestEvent } from '@sveltejs/kit';
import { Yoga } from '$lib/yoga';
const yogaApp = createYoga<RequestEvent>({
schema: createSchema({
typeDefs: `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'SvelteKit - GraphQL Yoga'
}
}
}),
// Needed to be defined explicitly because our endpoint lives at a different path other than `/graphql`
graphqlEndpoint: '/api/graphql',
// Needed to let Yoga use sveltekit's Response object
fetchAPI: { Response }
});
export { yogaApp as GET, yogaApp as POST };
export { Yoga as GET, Yoga as POST };