add config
This commit is contained in:
parent
21634249d7
commit
05a95b72d0
8 changed files with 44 additions and 5 deletions
24
src/lib/config/index.ts
Normal file
24
src/lib/config/index.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { logger } from '$lib/logger';
|
||||
import { z } from 'zod';
|
||||
|
||||
export interface Configuration {
|
||||
app_version: string;
|
||||
}
|
||||
|
||||
export const LoadConfig = (): Configuration => {
|
||||
const { success, data, error } = z
|
||||
.object({
|
||||
VITE_APP_VERSION: z.string().default('development')
|
||||
})
|
||||
.safeParse(import.meta.env);
|
||||
|
||||
if (!success) {
|
||||
logger.error(error.message);
|
||||
}
|
||||
|
||||
return {
|
||||
app_version: data!.VITE_APP_VERSION
|
||||
};
|
||||
};
|
||||
|
||||
export const Config = LoadConfig();
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
import { Context } from '$lib/yoga/context';
|
||||
import SchemaBuilder from '@pothos/core';
|
||||
|
||||
export const builder = new SchemaBuilder({});
|
||||
type ContextType = ReturnType<typeof Context>;
|
||||
|
||||
export const builder = new SchemaBuilder<{ Context: ContextType }>({});
|
||||
|
||||
builder.queryType({
|
||||
fields: (t) => ({
|
||||
version: t.string({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
resolve: (parent, args, context) => '1.0.0-alpha'
|
||||
resolve: (parent, args, context) => context.config.app_version
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
|
|||
7
src/lib/yoga/context.ts
Normal file
7
src/lib/yoga/context.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Config } from '$lib/config';
|
||||
import type { YogaInitialContext } from 'graphql-yoga';
|
||||
|
||||
export const Context = (initialContext: YogaInitialContext) => ({
|
||||
...initialContext,
|
||||
config: Config
|
||||
});
|
||||
|
|
@ -2,8 +2,10 @@ 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue