mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
Add sequelize index file
This commit is contained in:
parent
6f00481c25
commit
d20b00532d
12 changed files with 77 additions and 50 deletions
|
|
@ -4,24 +4,21 @@ import { SchemaLink } from "@apollo/client/link/schema"
|
|||
import { makeExecutableSchema } from "@graphql-tools/schema";
|
||||
import { getSession } from 'auth-astro/server';
|
||||
import type { Session } from '@auth/core/types';
|
||||
|
||||
import { typeDefs } from "./__generated__/typeDefs.generated";
|
||||
import resolvers from '@/graphql/resolvers'
|
||||
import type { MySqlDialect } from '@sequelize/mysql';
|
||||
import { Sequelize, type ModelStatic, type Options } from '@sequelize/core'
|
||||
|
||||
import db from '@/sequelize';
|
||||
|
||||
const schema = makeExecutableSchema({ typeDefs, resolvers })
|
||||
export type ResolverContext = { request?: Request, session?: Session }
|
||||
|
||||
const envOptions: Options<MySqlDialect> = JSON.parse(import.meta.env.SEQUELIZE) || {}
|
||||
|
||||
export async function getApolloClient(request?: Request) {
|
||||
const session = request ? await getSession(request) : null
|
||||
const db = new Sequelize(envOptions)
|
||||
envOptions.models = Object.values<ModelStatic>(await import.meta.glob('@/sequelize/models/**/*.ts', { eager: true, import: 'default' }))
|
||||
|
||||
return new ApolloClient({
|
||||
ssrMode: true,
|
||||
link: new SchemaLink({ schema, context: { request, session } }),
|
||||
link: new SchemaLink({ schema, context: { request, session, db } }),
|
||||
cache: new InMemoryCache()
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue