How to use the type-graphql.useContainer function in type-graphql

To help you get started, we’ve selected a few type-graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anttiviljami / serverless-type-graphql-boilerplate / src / handler.ts View on Github external
import * as TypeGraphQL from 'type-graphql';

import { Container } from 'typedi';

import { RecipeResolver } from "./resolvers/recipe-resolver";
import { RateResolver } from "./resolvers/rate-resolver";
import { Recipe } from "./entities/recipe";
import { Rate } from "./entities/rate";
import { User } from "./entities/user";

export interface UserContext {
  user: User;
}

// register 3rd party IOC container
TypeGraphQL.useContainer(Container);
TypeORM.useContainer(Container);

async function bootstrap(event: APIGatewayProxyEvent, context: Context, callback: Callback) {
  try {
    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,
    });
github TypedProject / ts-express-decorators / packages / graphql / src / services / GraphQLService.ts View on Github external
} = settings;

    if (this.has(id)) {
      return await this.get(id)!;
    }

    $log.info(`Create server with apollo-server-express for: ${id}`);
    $log.debug(`options: ${JSON.stringify({path})}`);

    try {
      // istanbul ignore next
      // @ts-ignore
      if (typeGraphql.useContainer) {
        // support old version of type-graphql under @v0.17
        // @ts-ignore
        typeGraphql.useContainer(this.injectorService);
      }

      const schema = await this.createSchema({
        container: this.injectorService,
        ...buildSchemaOptions,
        resolvers: [...this.getResolvers(), ...resolvers, ...(buildSchemaOptions.resolvers || [])]
      });

      const defaultServerConfig = {
        ...serverConfig,
        dataSources: this.createDataSources(dataSources, serverConfig.dataSources),
        schema
      };

      const server = customServer ? customServer(defaultServerConfig) : new ApolloServer(defaultServerConfig);
github Balyaak / create-typeorm-apollo-server / packages / server / src / index.ts View on Github external
import * as Redis from "ioredis";

import { Container } from "typedi";
import * as TypeORM from "typeorm";
import * as TypeGraphQL from "type-graphql";

import chalk from "chalk";
import * as Listr from "listr";

import { Observable } from "rxjs";
import { customAuthChecker } from "./utils/authChecker";

const RedisStore = connectRedis(session as any);

// register 3rd party IOC container
TypeGraphQL.useContainer(Container);
TypeORM.useContainer(Container);

const bootstrap = new Listr(
  [
    {
      title: "Database",
      task: () =>
        TypeORM.createConnection()
          .catch(e => {
            return Promise.reject(e);
          })
          .then(() => Promise.resolve())
    },
    {
      title: "Creating express app instance",
      task: (ctx: any) => {
github benawad / codeponder / packages / server / src / index.ts View on Github external
import { DisplayError } from "./errors/DisplayError";
import { commentLoader } from "./loaders/commentLoader";
import { userLoader } from "./loaders/userLoader";
import { redis } from "./redis";
import { createUser } from "./utils/createUser";
import { logManager } from "./utils/logManager";
import { setupErrorHandling } from "./utils/shutdown";
require("dotenv-safe").config();

const logger = logManager();
logger.info("Loading environment...");

const SESSION_SECRET = process.env.SESSION_SECRET;
const RedisStore = connectRedis(session); // connect node.req.session to redis backing store

useContainer(Container);
typeorm.useContainer(Container);

const startServer = async (): Promise => {
  logger.info("Connecting database...");
  const conn = await createTypeormConn();
  if (conn) {
    logger.info("database connected ");
    await conn.runMigrations();
  }
  logger.info("Creating express server...");
  const app = express();

  logger.info("Creating GQL server...");
  const server = new ApolloServer({
    schema: await buildSchema({
      resolvers: [__dirname + "/modules/**/resolver.*"],
github mgm-interns / team-radio / server / src / index.ts View on Github external
import 'reflect-metadata';
import { bootstrap } from 'config';
import * as TypeGraphQL from 'type-graphql';
import { Container } from 'typedi';
import * as TypeORM from 'typeorm';
import polyfill from 'config/polyfill';

polyfill();

TypeGraphQL.useContainer(Container);
TypeORM.useContainer(Container);

bootstrap();
github niklaskorz / nkchat / server / src / index.ts View on Github external
import 'reflect-metadata';

import * as typegraphql from 'type-graphql';
import { Container } from 'typedi';
import * as typeorm from 'typeorm';
import winston from 'winston';
import * as config from './config';
import { Message, Room, User } from './models';
import startServer from './startServer';

typeorm.useContainer(Container);
typegraphql.useContainer(Container);

const console = new winston.transports.Console({
  format: winston.format.simple(),
});
winston.add(console);

const createDatabaseConnection = () =>
  typeorm.createConnection({
    type: 'mongodb',
    url: `mongodb://${config.mongodbHost}/nkchat`,
    entities: [Message, Room, User],
    synchronize: true,
    useNewUrlParser: true,
  });

createDatabaseConnection()
github w3tecch / express-typescript-boilerplate / src / loaders / iocLoader.ts View on Github external
export const iocLoader: MicroframeworkLoader = (settings: MicroframeworkSettings | undefined) => {

    /**
     * Setup routing-controllers to use typedi container.
     */
    routingUseContainer(Container);
    ormUseContainer(Container);
    classValidatorUseContainer(Container);
    typeGraphQLUseContainer(Container);
};