@server Directive

The @server directive configures core behavior of the GQLForge GraphQL server, including networking, validation, and runtime options.

Fields

FieldTypeDefaultDescription
apollo_tracingBooleanfalseEnable Apollo Tracing extensions in responses for performance profiling.
batch_requestsBooleanfalseAllow batched GraphQL queries in a single HTTP request.
headersHeadersnullGlobal response headers applied to every outgoing HTTP response.
global_response_timeoutIntnullMaximum time in milliseconds before a request is terminated.
hostnameString"0.0.0.0"Network interface address the server binds to.
introspectionBooleantrueEnable the GraphQL introspection system. Disable in production for security.
enable_federationBooleanfalseExpose Apollo Federation entity service fields (_entities, _service).
pipeline_flushBooleantrueFlush the response pipeline after each chunk for lower latency.
portInt8000TCP port the server listens on.
query_validationBooleantrueValidate incoming queries against the schema before execution.
response_validationBooleanfalseValidate resolver responses against the expected return types.
scriptScriptOptionsnullConfiguration for the embedded JavaScript runtime.
showcaseBooleanfalseEnable the built-in GraphQL playground UI at the server root.
spaSpanullSingle-page application hosting configuration.

Example

schema
@server(
  port: 4000
  hostname: "0.0.0.0"
  global_response_timeout: 30000
  introspection: true
  query_validation: true
  response_validation: false
  batch_requests: true
  showcase: true
) {
  query: Query
}

type Query {
  hello: String @expr(body: "Hello, world!")
}

This configuration starts the server on port 4000, enables batching, and exposes the playground UI.

SPA Hosting

The spa field enables single-page application hosting from a specified directory with client-side routing support.

Spa Fields

FieldTypeRequiredDescription
dirStringYesPath to the directory containing SPA static assets. Must contain index.html.

Routing Behavior

  • File-like paths (/assets/app.js, /style.css): Served if the file exists, otherwise 404.
  • Non-file paths (/dashboard, /users/123): Return index.html for client-side routing.
  • API / GraphQL routes: Take priority over SPA (/graphql, /api/*, /status, etc. are unaffected).

Example

schema
@server(
  port: 4000
  spa: { dir: "./dist" }
) {
  query: Query
}

This serves the SPA from the ./dist directory. Requests like /dashboard return index.html, while /assets/app.js serves the actual file.