Skip to content

Application

Application in @evolve-framework/core

Application composes a Module with its HTTP/GraphQL surface and runs it.

Lifecycle:

  1. new Application(options) — cheap, no side effects.
  2. await service.init() — runs module.init() then builds the GraphQL and Fastify instances. Idempotent.
  3. await service.start() — runs onStart, binds the port and installs signal handlers. A signal-driven shutdown runs stop(), then onShutdown.

Tests can use service.fastify.inject(...) after init() without calling start(). Use createApplication for the common one-liner that does steps 1 and 2 together.

The GraphQL user-context type lives on ApplicationOptions<TUserContext> (where it couples graphql.context to graphql.plugins), not on the service itself — the service exposes nothing typed by it.

import { Application } from "@evolve-framework/core";
new Application(options: ApplicationOptions<any>)
OptionTypeDescription
namestring

The name of the domain service, used for identification and logging.

moduleModule<any>

The module that encapsulates the domain's business logic, GraphQL schema, and resolvers. This is a required property as the domain service relies on the module to define its functionality.

httpHTTPServerOptions

HTTP server configuration. Required to start the HTTP server that handles both GraphQL and REST requests.

onStart?(() => void | Promise<void>)

Sets up what the modules share, such as the cache connection, when start() is called and before the server listens. A rejection is a failed startup: the process shuts down and exits.

onShutdown?(() => void | Promise<void>)

Releases what a finished onStart acquired, after stop(), when the process shuts down on a signal. A direct stop() does not run it.

graphql?GraphQLOptions<any>

Optional GraphQL server configuration. This is only used if the module provides a GraphQL configuration. If the module does not provide a GraphQL configuration, this property is ignored.

MethodDescription
init(): Promise<void>Runs module.init(), then builds the GraphQL and Fastify servers from the module and the options.
start(): Promise<void>Runs onStart, binds the HTTP server to http.address and installs signal handlers that run stop() and then onShutdown.
stop(): Promise<void>Closes HTTP (draining open requests), disposes GraphQL, then closes the module.
getYogaInstance(): GraphQLInstance<ServerContext, any> | undefinedThe GraphQL server, or undefined before init() or when the module serves no GraphQL.