How to use the type-graphql.buildSchema 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
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);
}
github MichalLytek / type-graphql / examples / basic / index.ts View on Github external
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({
github goldcaddy77 / warthog / src / core / code-generator.ts View on Github external
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;
github ReactFinland / graphql-api / server / schema / index.ts View on Github external
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
  });
}
github forsigner / egg-type-graphql / lib / GraphQLServer.ts View on Github external
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);
    }
  }
github mabuonomo / yggdrasil-ts / server.ts View on Github external
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
            })));
    }
}
github forsigner / egg-type-graphql / lib / GraphQLServer.js View on Github external
async getSchema() {
        const resolvers = this.loadResolvers();
        return await type_graphql_1.buildSchema({
            resolvers,
            dateScalarMode: 'timestamp',
            emitSchemaFile: true,
        });
    }
    async start() {
github NoQuarterTeam / fullstack-boilerplate / packages / api / src / index.ts View on Github external
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,
    })