You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/aws/services/appsync.mdx
+150Lines changed: 150 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -204,9 +204,141 @@ Pipeline resolvers, on the other hand, invoke AppSync functions that wraps the A
204
204
Unit resolvers are written in the Velocity templating language (VTL), while pipeline resolvers can be written in either VTL or JavaScript.
205
205
206
206
207
+
### WebSocket Subscriptions
208
+
209
+
LocalStack supports real-time GraphQL subscriptions over WebSocket for AWS AppSync APIs.
210
+
211
+
Clients can subscribe to mutation-triggered events and receive updates in real time via the AppSync WebSocket endpoint. LocalStack supports the GraphQL `@aws_subscribe` directive, and core subscription message flow. Use this feature to power live updates in apps such as chat, dashboards, or collaborative editors. There's no need to poll for changes.
212
+
213
+
You can set up a GraphQL subscription in your schema, connect to the WebSocket endpoint, and receive live updates triggered by a mutation.
214
+
215
+
#### 1. Extend Your GraphQL Schema
216
+
217
+
First, ensure your schema includes a `subscription` type. Use the `@aws_subscribe` directive to link each subscription to a corresponding mutation.
218
+
219
+
```graphql
220
+
typeMessage {
221
+
id: ID!
222
+
content: String!
223
+
}
224
+
225
+
typeMutation {
226
+
postMessage(id: ID!, content: String!): Message!
227
+
}
228
+
229
+
typeSubscription {
230
+
onMessagePosted: Message
231
+
@aws_subscribe(mutations: ["postMessage"])
232
+
}
233
+
234
+
schema {
235
+
query: Query
236
+
mutation: Mutation
237
+
subscription: Subscription
238
+
}
239
+
```
240
+
241
+
#### 2. Connect to the WebSocket Endpoint
242
+
243
+
LocalStack exposes a WebSocket endpoint for each GraphQL API:
|`connection_ack`| Server acknowledges the connection |
331
+
|`start`| Starts a subscription |
332
+
|`start_ack`| Acknowledges a successful subscription |
333
+
|`data`| Sends a message when a matching mutation occurs |
334
+
|`stop`| Client unsubscribes from a subscription |
335
+
|`complete`| Server confirms unsubscription |
336
+
337
+
207
338
### Configuring GraphQL endpoints
208
339
209
340
There are three configurable strategies that govern how GraphQL API endpoints are created.
341
+
210
342
The strategy can be configured via the `GRAPHQL_ENDPOINT_STRATEGY` environment variable.
211
343
212
344
| Value | Format | Description |
@@ -216,6 +348,24 @@ The strategy can be configured via the `GRAPHQL_ENDPOINT_STRATEGY` environment v
216
348
|`legacy`|`localhost:4566/graphql/<api-id>`| This strategy represents the old endpoint format, which is currently the default but will eventually be phased out. |
217
349
218
350
351
+
In addition to the GraphQL HTTP endpoint, each AppSync API also provides a WebSocket endpoint for GraphQL subscriptions.
352
+
353
+
The WebSocket server runs on a separate port that may change between deployments. To ensure correct connectivity, always use the `REALTIME` URL returned in the `uris` field of the `create-graphql-api` or `get-graphql-api` responses.
The `REALTIME` endpoint will ignore the `GRAPHQL_ENDPOINT_STRATEGY` and always use the `legacy` strategy.
366
+
:::
367
+
368
+
219
369
### GraphQL Resource Browser
220
370
221
371
The LocalStack Web Application provides a Resource Browser for managing AppSync APIs, Data Sources, Schema, Query, Types, Resolvers, Functions and API keys.
0 commit comments