You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
demo-graphql-oauth/src/app/schema.ts

43 lines
1.1 KiB

require("dotenv").config()
import { DocumentNode, graphql, GraphQLSchema } from "graphql"
import { buildSchema } from "type-graphql"
import { ConnectionOptions } from "typeorm"
import { UserResolver } from "./UserResolver"
import { customAuthChecker } from "./userResolver/auth"
import { User } from "./userResolver/User"
let schema: GraphQLSchema
export const callSchema = async (document: DocumentNode, context?: any) => {
if (!schema) {
schema = await createSchema()
}
return graphql({
schema,
source: document.loc!.source.body,
contextValue: context,
})
}
export const createSchema = () =>
buildSchema({
resolvers: [UserResolver],
authChecker: customAuthChecker,
})
export const connectionOptionsforTesting = () => {
let connectionOptions: ConnectionOptions = {
type: "postgres",
host: process.env.DB_HOST,
port: 5432,
database: "testing",
username: process.env.DB_USER,
password: process.env.DB_PASS,
entities: [User],
synchronize: true,
logging: false,
}
return connectionOptions
}