Skip to content

Class: ApolloService

Defined in: packages/apollo/src/services/apollo.service.ts:30

Service for managing Apollo Server instance and GraphQL operations. Handles schema resolution, server startup, context creation, and WebSocket subscriptions.

Constructors

Constructor

ts
new ApolloService(options?, elysiaApp?): ApolloService;

Defined in: packages/apollo/src/services/apollo.service.ts:41

Creates a new ApolloService instance.

Parameters

ParameterTypeDescription
optionsApolloOptionsGraphQL configuration options.
elysiaApp?Elysia<"", { decorator: { }; derive: { }; resolve: { }; store: { }; }, { error: { }; typebox: { }; }, { macro: { }; macroFn: { }; parser: { }; response: { }; schema: { }; standaloneSchema: { }; }, { }, { derive: { }; resolve: { }; response: { }; schema: { }; standaloneSchema: { }; }, { derive: { }; resolve: { }; response: { }; schema: { }; standaloneSchema: { }; }>Elysia application instance (for WebSocket support).

Returns

ApolloService

Methods

createContext()

ts
createContext(elysiaContext): Promise<unknown>;

Defined in: packages/apollo/src/services/apollo.service.ts:97

Creates a GraphQL context for a request.

Parameters

ParameterTypeDescription
elysiaContext{ body: unknown; cookie: Record<string, Cookie<unknown>>; headers: Record<string, string | undefined>; params: Record<string, string>; path: string; query: Record<string, string>; redirect: (url, status?) => Response; request: Request; route: string; server: Server<unknown> | null; set: { cookie?: Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>; headers: HTTPHeaders; redirect?: string; status?: | number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"; }; status: <Code, T>(code, response?) => ElysiaCustomStatusResponse<Code, T, Code extends | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? { Accepted: 202; Already Reported: 208; Bad Gateway: 502; Bad Request: 400; Conflict: 409; Continue: 100; Created: 201; Early Hints: 103; Enhance Your Calm: 420; Expectation Failed: 417; Failed Dependency: 424; Forbidden: 403; Found: 302; Gateway Timeout: 504; Gone: 410; HTTP Version Not Supported: 505; I'm a teapot: 418; Insufficient Storage: 507; Internal Server Error: 500; Length Required: 411; Locked: 423; Loop Detected: 508; Method Not Allowed: 405; Misdirected Request: 421; Moved Permanently: 301; Multi-Status: 207; Multiple Choices: 300; Network Authentication Required: 511; No Content: 204; Non-Authoritative Information: 203; Not Acceptable: 406; Not Extended: 510; Not Found: 404; Not Implemented: 501; Not Modified: 304; OK: 200; Partial Content: 206; Payload Too Large: 413; Payment Required: 402; Permanent Redirect: 308; Precondition Failed: 412; Precondition Required: 428; Processing: 102; Proxy Authentication Required: 407; Range Not Satisfiable: 416; Request Header Fields Too Large: 431; Request Timeout: 408; Reset Content: 205; See Other: 303; Service Unavailable: 503; Switching Protocols: 101; Temporary Redirect: 307; Too Early: 425; Too Many Requests: 429; Unauthorized: 401; Unavailable For Legal Reasons: 451; Unprocessable Content: 422; Unsupported Media Type: 415; Upgrade Required: 426; URI Too Long: 414; Variant Also Negotiates: 506; }[Code] : Code>; store: { }; }The Elysia request context.
elysiaContext.bodyunknown-
elysiaContext.cookieRecord<string, Cookie<unknown>>-
elysiaContext.headersRecord<string, string | undefined>-
elysiaContext.paramsRecord<string, string>-
elysiaContext.pathstringPath extracted from incoming URL Represent a value extracted from URL Example '/id/9'
elysiaContext.queryRecord<string, string>-
elysiaContext.redirect(url, status?) => Response-
elysiaContext.requestRequest-
elysiaContext.routestringPath as registered to router Represent a path registered to a router, not a URL Example '/id/:id'
elysiaContext.serverServer<unknown> | null-
elysiaContext.set{ cookie?: Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>; headers: HTTPHeaders; redirect?: string; status?: | number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"; }-
elysiaContext.set.cookie?Record<string, { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; partitioned?: boolean; path?: string; priority?: "low" | "medium" | "high"; sameSite?: boolean | "lax" | "strict" | "none"; secrets?: string | (string | null)[] | null; secure?: boolean; value?: unknown; }>! Internal Property Use Context.cookie instead
elysiaContext.set.headersHTTPHeaders-
elysiaContext.set.redirect?stringDeprecated Use inline redirect instead Example Migration example new Elysia() .get(({ redirect }) => redirect('/'))
elysiaContext.set.status?| number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required"-
elysiaContext.status<Code, T>(code, response?) => ElysiaCustomStatusResponse<Code, T, Code extends | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? { Accepted: 202; Already Reported: 208; Bad Gateway: 502; Bad Request: 400; Conflict: 409; Continue: 100; Created: 201; Early Hints: 103; Enhance Your Calm: 420; Expectation Failed: 417; Failed Dependency: 424; Forbidden: 403; Found: 302; Gateway Timeout: 504; Gone: 410; HTTP Version Not Supported: 505; I'm a teapot: 418; Insufficient Storage: 507; Internal Server Error: 500; Length Required: 411; Locked: 423; Loop Detected: 508; Method Not Allowed: 405; Misdirected Request: 421; Moved Permanently: 301; Multi-Status: 207; Multiple Choices: 300; Network Authentication Required: 511; No Content: 204; Non-Authoritative Information: 203; Not Acceptable: 406; Not Extended: 510; Not Found: 404; Not Implemented: 501; Not Modified: 304; OK: 200; Partial Content: 206; Payload Too Large: 413; Payment Required: 402; Permanent Redirect: 308; Precondition Failed: 412; Precondition Required: 428; Processing: 102; Proxy Authentication Required: 407; Range Not Satisfiable: 416; Request Header Fields Too Large: 431; Request Timeout: 408; Reset Content: 205; See Other: 303; Service Unavailable: 503; Switching Protocols: 101; Temporary Redirect: 307; Too Early: 425; Too Many Requests: 429; Unauthorized: 401; Unavailable For Legal Reasons: 451; Unprocessable Content: 422; Unsupported Media Type: 415; Upgrade Required: 426; URI Too Long: 414; Variant Also Negotiates: 506; }[Code] : Code>-
elysiaContext.store{ }-

Returns

Promise<unknown>

The GraphQL context.


getServer()

ts
getServer(): ApolloServer<BaseContext> | undefined;

Defined in: packages/apollo/src/services/apollo.service.ts:88

Gets the Apollo Server instance.

Returns

ApolloServer<BaseContext> | undefined

The ApolloServer instance or undefined if not started.


start()

ts
start(): Promise<void>;

Defined in: packages/apollo/src/services/apollo.service.ts:53

Starts the Apollo Server and registers WebSocket handlers if configured.

Returns

Promise<void>


stop()

ts
stop(): Promise<void>;

Defined in: packages/apollo/src/services/apollo.service.ts:79

Stops the Apollo Server.

Returns

Promise<void>

Released under the MIT License.