Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await TypeORM.getConnection();
} catch (err) {
await TypeORM.createConnection({
type: 'postgres',
url: process.env.DATABASE_URL,
entities: [Recipe, Rate, User],
synchronize: true,
logger: 'advanced-console',
logging: 'all',
dropSchema: true,
cache: true,
});
}
// build TypeGraphQL executable schema
(global as any).schema = (global as any).schema || await TypeGraphQL.buildSchema({
resolvers: [RecipeResolver, RateResolver],
validate: false,
});
const schema = (global as any).schema;
const server = new ApolloServer({ schema });
server.createHandler()(event, context, callback);
}
async function main() {
const schema = await buildSchema({
resolvers: [
CustomUserResolver,
UserRelationsResolver,
UserCrudResolver,
PostRelationsResolver,
PostCrudResolver,
],
emitSchemaFile: path.resolve(__dirname, "./generated-schema.graphql"),
validate: false,
});
const photon = new Photon({
// debug: true, // uncomment to see how dataloader for relations works
});
const server = new ApolloServer({
private async buildGraphQLSchema(): Promise {
if (!this.schema) {
debug('code-generator:buildGraphQLSchema:start');
debug(this.options.resolversPath);
this.schema = await buildSchema({
// TODO: we should replace this with an empty authChecker
// Note: using the base authChecker here just to generated the .graphql file
// it's not actually being utilized here
authChecker,
scalarsMap: [
{
type: 'ID' as any,
scalar: GraphQLID
}
],
resolvers: this.options.resolversPath
});
debug('code-generator:buildGraphQLSchema:end');
}
return this.schema;
export default async function generateSchema() {
return await buildSchema({
resolvers: Object.values(resolvers),
// scalarsMap: [{ type: Url, scalar: UrlScalar }],
// TODO: Emitting the schema could be useful for query checks.
// emitSchemaFile: true, // use path for a specific location
});
}
async getSchema() {
const { scalarsMap = [], dateScalarMode } = this.graphqlConfig;
let schema: GraphQLSchema;
const resolvers = this.loadResolvers();
if (!resolvers.length) return null;
const defaultScalarMap = [
{
type: Date,
scalar: dateScalarMode === 'timestamp' ? GraphQLTimestamp : GraphQLISODateTime,
},
];
try {
schema = await buildSchema({
resolvers,
dateScalarMode: 'isoDate',
scalarsMap: [ ...defaultScalarMap, ...scalarsMap ],
emitSchemaFile: true,
validate: this.graphqlConfig.validate,
globalMiddlewares: this.graphqlConfig.globalMiddlewares || [],
container: Container,
});
return this.setDirective(schema);
} catch (e) {
this.app.logger.error('[egg-type-graphql]', e);
}
}
private async setRouter() {
const schemaSign = await buildSchema({
resolvers: [SignResolver, SocialResolver]
});
this.express.use('/sign',
graphqlHTTP((req, res, next) => ({
schema: schemaSign,
graphiql: true,
req: req,
res: res,
next: next
})));
const schemaApi = await buildSchema({
resolvers: [UserResolver]
});
this.express.use('/api',
passport.authenticate('jwt',
{
session: false
}),
graphqlHTTP((req) => ({
schema: schemaApi,
graphiql: true,
context: req.user
})));
}
}
async getSchema() {
const resolvers = this.loadResolvers();
return await type_graphql_1.buildSchema({
resolvers,
dateScalarMode: 'timestamp',
emitSchemaFile: true,
});
}
async start() {
async function main() {
try {
await createDbConnection()
const app = express()
.enable("trust proxy")
.use(morgan("dev"))
.use(session)
const schema = await buildSchema({
authChecker,
authMode: "null",
container: Container,
resolvers: [__dirname + resolverPaths],
})
const apolloServer = new ApolloServer({
context: ({ req, res }: { req: Request; res: Response }) => ({
req,
res,
}),
introspection: true,
playground: true,
schema,
})