![]() ![]() No additional libraries or configuration are required. Your server receives the connectionParams object and can use it to perform authentication, along with any other connection-related tasks. Your GraphQLWsLink passes the connectionParams object to your server whenever it connects. The following commentAdded subscription notifies a subscribing client whenever a new comment is added to a particular blog post (specified by postID ): You define available subscriptions in your GraphQL schema as field s of the Subscription type. You define a subscription on both the server side and the client side, just like you do for queries and mutation s. To use Apollo Client with a GraphQL endpoint that supports multipart subscriptions over HTTP, make sure you're using version 3.7.11 or later.Īside from updating your client version, no additional configuration is required! Apollo Client automatically sends the required headers with the request if the terminating HTTPLink is passed a subscription operation. Note : Confusingly, the subscriptions-transport-ws library calls its WebSocket subprotocol graphql-ws, and the graphql-ws library calls its subprotocol graphql-transport-ws ! In this article, we refer to the two libraries ( subscriptions-transport-ws and graphql-ws ), not the two subprotocols. For example, a chat application's client wants to receive new messages as soon as they're available. Instead, you can fetch the object's initial state with a query, and your server can proactively push updates to individual field s as they occur. Repeatedly polling for a large object is expensive, especially when most of the object's field s rarely change. ![]() Small, incremental changes to large objects. You should use subscriptions for the following: Instead, you should poll intermittently with queries, or re-execute queries on demand when a user performs a relevant action (such as clicking a button). In the majority of cases, your client should not use subscriptions to stay up to date with your backend. Subscriptions are useful for notifying your client in real time about changes to back-end data, such as the creation of a new object or updates to an important field. They can maintain an active connection to your GraphQL server (most commonly via WebSocket), enabling the server to push updates to the subscription's result. Unlike queries, subscriptions are long-lasting operation s that can change their result over time. Like queries, subscriptions enable you to fetch data. In addition to queries and mutations, GraphQL supports a third operation type: subscriptions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |