42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import {
|
|
URLTypeDefinition,
|
|
URLResolver,
|
|
HexColorCodeDefinition,
|
|
HexColorCodeResolver,
|
|
} from 'graphql-scalars'
|
|
|
|
import { isProduction } from '@redwoodjs/api/logger'
|
|
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
|
|
import { createGraphQLHandler } from '@redwoodjs/graphql-server'
|
|
|
|
import directives from 'src/directives/**/*.{js,ts}'
|
|
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
|
|
import services from 'src/services/**/*.{js,ts}'
|
|
|
|
import { cookieName, getCurrentUser } from 'src/lib/auth'
|
|
import { db } from 'src/lib/db'
|
|
import { logger } from 'src/lib/logger'
|
|
|
|
const authDecoder = createAuthDecoder(cookieName)
|
|
|
|
export const handler = createGraphQLHandler({
|
|
authDecoder,
|
|
getCurrentUser,
|
|
loggerConfig: { logger, options: {} },
|
|
directives,
|
|
sdls,
|
|
services,
|
|
schemaOptions: {
|
|
typeDefs: [URLTypeDefinition, HexColorCodeDefinition],
|
|
resolvers: {
|
|
URL: URLResolver,
|
|
HexColorCode: HexColorCodeResolver,
|
|
},
|
|
},
|
|
cors: {
|
|
origin: isProduction ? process.env.ADDRESS_PROD : process.env.ADDRESS_DEV,
|
|
credentials: isProduction,
|
|
},
|
|
onException: () => db.$disconnect(),
|
|
})
|