0Pricing
Spring Boot 4 Complete Guide · Lesson

Subscriptions, Errors, and Schema Security

Stream real-time updates over subscriptions and harden the schema with field-level authorization.

Beyond Query and Mutation

Spring for GraphQL supports three root operation types. So far you have used Query (read) and Mutation (write). The third is Subscription — a long-lived stream that pushes data to the client whenever a server-side event occurs.

  • Query/Mutation: one request, one response.
  • Subscription: one request, many responses over time.

In this lesson you will stream live updates with subscriptions, shape GraphQL errors cleanly, and lock down individual fields with method security.

Declaring a Subscription in the Schema

Subscriptions are declared in the GraphQL schema just like queries. Each subscription field describes a stream of a given type. Below, messageAdded streams a Message for a particular room.

The transport for subscriptions is typically WebSocket (graphql-ws protocol), so make sure your client connects over ws:// rather than plain HTTP POST.

type Subscription {
  messageAdded(roomId: ID!): Message!
}

type Message {
  id: ID!
  roomId: ID!
  text: String!
  author: String!
}

All lessons in this course

  1. Schema-First Design and Type Mapping
  2. Data Fetchers and Argument Binding
  3. Solving N+1 with Batch Loaders
  4. Subscriptions, Errors, and Schema Security
← Back to Spring Boot 4 Complete Guide