Back to results for “GraphQL”
Flutter › GraphQL in Flutter

How do GraphQL subscriptions let a Flutter app receive genuinely real time updates whenever specific relevant data actually changes on the server, similar conceptually to how a Firestore real time listener already works?

Intermediate

Answer

A GraphQL subscription establishes a genuinely persistent, ongoing connection, typically using WebSockets underneath, letting your Flutter app receive a brand new update message automatically pushed directly from the server the instant some genuinely relevant specific piece of data actually changes, rather than your app needing to repeatedly and wastefully poll the server itself by making a genuinely brand new separate request over and over again, and this is conceptually quite similar to how a Firestore real time listener already properly works, though it specifically operates through the underlying GraphQL protocol rather than through Firebase's own particular specific proprietary system.
Subscription(
  options: SubscriptionOptions(document: gql(orderStatusSubscription)),
  builder: (result) {
    return Text('Status: ${result.data?['orderStatusChanged']['status']}');
  },
)
Real-world example A food delivery app uses a GraphQL subscription to automatically display a customer's own order status updating genuinely instantly and in real time the very moment the restaurant actually marks that exact same specific order as ready, without the app ever needing to repeatedly poll the server itself.

Common follow-ups: What genuinely underlying network protocol do GraphQL subscriptions typically actually rely on?;How do you properly and correctly handle a subscription connection that genuinely gets unexpectedly dropped, such as when a device briefly loses its internet connection?