Application
This guide explains how to set up a Baeta application and integrate it with a GraphQL server.
Module Registration
Baeta automatically collects and exports all modules in src/modules/index.ts. Simply import them and pass to createApplication:
// src/app.ts
import { createApplication } from "@baeta/core";
import modules from "./modules/index.ts";
const baeta = createApplication({
modules,
});
Server Integration
GraphQL Yoga
import { createServer } from "node:http";
import { createApplication } from "@baeta/core";
import { createYoga } from "graphql-yoga";
import modules from "./modules/index.ts";
import type { Context, ServerContext } from "./types/context.ts";
const baeta = createApplication({
modules,
});
export const yoga = createYoga<ServerContext, Context>({
schema: baeta.schema,
context: {
appVersion: "1.0.0",
},
});
const server = createServer(yoga);
server.listen(4000, () => {
console.log(
`🚀 Server ready at http://localhost:4000${yoga.graphqlEndpoint}`,
);
});
Apollo Server
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { createApplication } from "@baeta/core";
import modules from "./modules/index.ts";
import type { Context } from "./types/context.ts";
const baeta = createApplication({
modules,
});
const server = new ApolloServer<Context>({
schema: baeta.schema,
});
const { url } = await startStandaloneServer(server, {
listen: { port: 4000 },
context: async () => ({
// your context here
}),
});
console.log(`🚀 Server ready at: ${url}`);