← API

API FEATURE

GraphQL API

If your public API is GraphQL-first, Semitexa still keeps the application layer explicit and typed.

Feature Guide

A quick orientation block that answers the essential questions: what this feature does, how it works, why it matters, and the key concepts behind it.

What this does

Semitexa can also serve GraphQL-first APIs. The public entrypoint is still POST /graphql, but the use case behind each field remains explicit through payload and output contracts.

How it works

A GraphQL-first operation declares #[ExposeAsGraphql(...)] on a dedicated payload and returns a typed output DTO. The transport may be GraphQL-only, but the application structure still avoids the usual resolver sprawl of ad-hoc field classes and improvised arrays.

Why it matters

This keeps GraphQL honest. Teams get the graph they want without paying for a second hidden application layer made of resolver glue.

Key concepts

POST /graphql
The public transport endpoint used by GraphQL clients.
GraphQL-first
A use case that is exposed only through the graph and does not need a public REST route.
typed output DTO
A concrete class that owns the public GraphQL response shape.

GraphQL API

GraphQL-first without resolver sprawl

The public entrypoint is POST /graphql. The important part is that Semitexa still keeps the use case explicit: one payload, one output contract, one graph field.

Transport POST /graphql
GraphQL field query.productMetrics
Returns ProductMetricsGraphqlView

Example query

query {
  productMetrics {
    total
    active
    archived
    averagePrice
  }
}

Example response

{
  "data": {
    "productMetrics": {
      "total": 128,
      "active": 117,
      "archived": 11,
      "averagePrice": 189.4
    }
  }
}
POST /graphql #[ExposeAsGraphql] typed output DTOs GraphQL-first

Verified against Semitexa Ultimate 2026.09.19.1020

GraphQL API

If your public API is GraphQL-first, Semitexa still keeps the application layer explicit and typed.

How it works

A GraphQL-only endpoint uses #[ExposeAsGraphql] on the Payload DTO to register the operation into the GraphQL schema under a declared field name and root type (Query or Mutation). The handler returns a typed output DTO — a plain PHP class — and the framework serializes it into the GraphQL response shape. No resolver classes, no schema-first string parsing, no separate type registry to maintain.

Why this matters

GraphQL-first Semitexa APIs still use typed payloads and typed output DTOs. The application logic lives in the handler, which keeps business code away from transport concerns. Adding a new GraphQL field means adding one Payload DTO with the attribute — the schema updates automatically on the next boot.

© Brian Kernighan: "Controlling complexity is the essence of computer programming."

GraphQL-Only Payload Trusted input boundary
<?phpdeclare(strict_types=1);namespace App\Api\Graphql;use App\Api\Graphql\Output\ProductMetricsGraphqlView;use Semitexa\Core\Attribute\AsPublicPayload;use Semitexa\Core\Http\Response\ResourceResponse;use Semitexa\Graphql\Attribute\ExposeAsGraphql;#[AsPublicPayload(    path: '/__graphql/products/metrics',    methods: ['POST'],    responseWith: ResourceResponse::class,)]#[ExposeAsGraphql(    field: 'productMetrics',    rootType: 'query',    output: ProductMetricsGraphqlView::class,)]final class ProductMetricsPayload{    protected string $status = 'active';    public function getStatus(): string { return $this->status; }    public function setStatus(string $status): void { $this->status = trim($status); }}

GraphQL-First

What this page is proving

Question Semitexa answer
Do I need a public REST route first? No. The public story can be POST /graphql from day one.
Does GraphQL push me into resolver classes everywhere? No. The use case still hangs on explicit payload and output contracts.
Where does the response shape live? In a typed output DTO instead of improvised arrays and field-by-field resolver glue.

How it works

A GraphQL-first operation declares #[ExposeAsGraphql(...)] on a dedicated payload and returns a typed output DTO. The transport may be GraphQL-only, but the application structure still avoids the usual resolver sprawl of ad-hoc field classes and improvised arrays.

Why it matters

This keeps GraphQL honest. Teams get the graph they want without paying for a second hidden application layer made of resolver glue.

Key concepts

POST /graphql
The public transport endpoint used by GraphQL clients.
GraphQL-first
A use case that is exposed only through the graph and does not need a public REST route.
typed output DTO
A concrete class that owns the public GraphQL response shape.

Support Semitexa
Built for developers who prefer control over magic. Your support helps keep it fast, open, and evolving.

Donate via PayPal