Class GraphQl
Handler around a graphql-java runtime.
var graphql = GraphQl.builder().schema(sdl).graphQL(applicationOwnedGraphQL).build();
app.post("/graphql", graphql.handler()); // nothing is served by default
The schema is accepted as SDL and parsed when the handler is built, so a bad schema fails at
configuration time. The application owns its graphql.GraphQL instance (its runtime
wiring, data fetchers and execution strategies) and passes it to GraphQl.Builder.graphQL(Object).
The parameter is deliberately typed as Object: no graphql-java type appears in an Axiom
signature, and the value is checked when the handler is built. When no instance is supplied the
adapter builds a read-only runtime from the SDL with graphql-java's default property fetchers.
The adapter adds its own instrumentation (query depth, query complexity, optional
introspection guard and the Axiom deadline) with GraphQL.transform, so the application's
instance is never mutated and its own instrumentation is retained. Each request gets a fresh
DataLoader registry (optionally filled by the application's own factory) and supports variables
and an operation name, and work is bounded by GraphQlOptions. Failures become
application/problem+json responses with fixed codes; GraphQL error messages, exception types and
stack traces never reach a client. Instances are immutable and thread-safe after construction; an
application-owned runtime must be thread-safe too.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aGraphQl; not thread-safe, build once at startup. -
Method Summary
Modifier and TypeMethodDescriptionstatic GraphQl.Builderbuilder()Starts a configuration.handler()Returns the handler to register on an Axiom route.options()Returns the bounds of this handler.register(Application app, String path, Middleware... middleware) Registers POST, and GET when enabled, on one path.
-
Method Details
-
builder
Starts a configuration. No route is registered until the caller registershandler()or callsregister(com.jsgalactic.axiom.application.Application, java.lang.String, com.jsgalactic.axiom.context.Middleware...).- Returns:
- a builder
-
options
Returns the bounds of this handler.- Returns:
- immutable options
-
handler
Returns the handler to register on an Axiom route.- Returns:
- thread-safe handler
-
register
Registers POST, and GET when enabled, on one path. Registration is explicit: an application that prefers to compose middleware itself can registerhandler()directly.- Parameters:
app- application still configuringpath- absolute route pathmiddleware- route middleware, outermost first- Returns:
- the POST route
-