Skip to content

Commit

Permalink
Merge branch 'main' into renovate/cimg-node-20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
alessbell authored Jun 21, 2023
2 parents b86fcfb + 6875b62 commit 70859c3
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 626 deletions.
5 changes: 0 additions & 5 deletions .changeset/clever-ravens-juggle.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/shiny-books-roll.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/spicy-waves-shake.md

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Add comment if no new changesets exist
if: ${{ steps.added-files.outputs.changesets == '' }}
uses: peter-evans/create-or-update-comment@v3.0.1
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand All @@ -106,7 +106,7 @@ jobs:

- name: Create comment
if: ${{ steps.added-files.outputs.changesets != '' }}
uses: peter-evans/create-or-update-comment@v3.0.1
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @apollo/client

## 3.7.16

### Patch Changes

- [#10806](https://github.com/apollographql/apollo-client/pull/10806) [`cb1540504`](https://github.com/apollographql/apollo-client/commit/cb15405041e0bd644fcf23d1b8fcaa09762c5a6a) Thanks [@phryneas](https://github.com/phryneas)! - Fix a bug in `PersistedQueryLink` that would cause it to permanently skip persisted queries after a 400 or 500 status code.

- [#10807](https://github.com/apollographql/apollo-client/pull/10807) [`b32369592`](https://github.com/apollographql/apollo-client/commit/b3236959269ce27b18b8c2cae72106098a3ba1b8) Thanks [@phryneas](https://github.com/phryneas)! - `PersistedQueryLink` will now also check for error codes in `extensions`.

- [#10982](https://github.com/apollographql/apollo-client/pull/10982) [`b9be7a814`](https://github.com/apollographql/apollo-client/commit/b9be7a814a64fc6b3e6ce23dd97a4f0c7140aba7) Thanks [@sdeleur-sc](https://github.com/sdeleur-sc)! - Update `relayStylePagination` to avoid populating `startCursor` when only a single cursor is present under the `edges` field. Use that cursor only as the `endCursor`.

- [#10962](https://github.com/apollographql/apollo-client/pull/10962) [`772cfa3cb`](https://github.com/apollographql/apollo-client/commit/772cfa3cb563dccee878177e58c8250c4e5b5013) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove `useGETForQueries` option in `BatchHttpLink.Options` type since it is not supported.

## 3.7.15

### Patch Changes
Expand Down
16 changes: 15 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🔮 Apollo Client Roadmap

**Last updated: 2023-05-30**
**Last updated: 2023-06-20**

For up to date release notes, refer to the project's [Changelog](https://github.com/apollographql/apollo-client/blob/main/CHANGELOG.md).

Expand Down Expand Up @@ -30,6 +30,20 @@ Currently in active development and in the beta stage. React 18 users will get

Try it today: `npm i @apollo/client@beta` and let us know what you think!

## [3.9.0](https://github.com/apollographql/apollo-client/milestone/32)

_Currently in planning phase_

Features we plan to tackle:

- Introduce a suspenseful `useFragment` that will suspend when the data is not yet loaded
- Ability to preload a query outside of a React component that can be used with `useReadQuery` to suspend while loading
- Introduce a new `useInteractiveQuery`/`useLazyBackgroundQuery` hook (name TBD)
- Add metrics integration throughout the library for powerful insights
- Improved testing utilities

> NOTE: These are subject to change and are not guaranteed to be part of 3.9 at the time of this writing.
## Future 3.x releases

_Approximate Date: TBD_
Expand Down
33 changes: 25 additions & 8 deletions docs/source/data/subscriptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,31 @@ You _should_ use subscriptions for the following:

> **Note**: Subscriptions cannot be used to listen to local client events, like subscribing to changes in the cache. Subscriptions are intended to be used to subscribe to external data changes, and have those received changes be stored in the cache. You can then leverage Apollo Client's observability model to watch for changes in the cache, using [`client.watchQuery`](../api/core/ApolloClient#ApolloClient.watchQuery) or [`useQuery`](../api/react/hooks#usequery).
## Choosing a subscription library
## Supported subscription protocols

The GraphQL spec does not define a specific protocol for sending subscription requests. The first popular JavaScript library to implement subscriptions over WebSocket is called `subscriptions-transport-ws`. **This library is no longer actively maintained.** Its successor is a library called `graphql-ws`. The two libraries _do not use the same WebSocket subprotocol_, so you need to make sure that your server and clients all use the same library.
The GraphQL spec does not define a specific protocol for sending subscription requests. Apollo Client supports the following protocols for subscriptions:

Apollo Client supports both `graphql-ws` and `subscriptions-transport-ws`. We recommend you use the newer library `graphql-ws`, and this page shows how to use it. If you need to use `subscriptions-transport-ws` because your server still uses that protocol, the differences are described [at the bottom of this page](#the-older-subscriptions-transport-ws-library).
- [**WebSocket**](#websocket-subprotocols), using one of the following subprotocols:
- [`graphql-ws`](https://github.com/enisdenjo/graphql-ws)
- [`subscriptions-transport-ws`](https://github.com/apollographql/subscriptions-transport-ws) (⚠️ unmaintained)
- [**HTTP**](#http), using chunked multipart responses **(Apollo Client `3.7.11` and later)**

> **You must use the same protocol as the GraphQL endpoint you're communicating with.**
### WebSocket subprotocols

The first popular JavaScript library to implement subscriptions over WebSocket is called `subscriptions-transport-ws`. **This library is no longer actively maintained.** Its successor is a library called `graphql-ws`. These two libraries _do not use the same WebSocket subprotocol_, so you need to use the same subprotocol that your GraphQL endpoint uses.

The [WebSocket setup](#websocket-setup) section below uses `graphql-ws`. If your endpoint uses `subscriptions-transport-ws`, see [this section](#the-older-subscriptions-transport-ws-library) for differences in configuration.

> **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.
### HTTP

To use Apollo Client with a GraphQL endpoint that supports [multipart subscriptions over HTTP](https://github.com/graphql/graphql-over-http/blob/main/rfcs/IncrementalDelivery.md), make sure you're using version `3.7.11` or later.

Aside 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.

## Defining a subscription

You define a subscription on both the server side and the client side, just like you do for queries and mutations.
Expand Down Expand Up @@ -78,11 +95,7 @@ Whenever your GraphQL server _does_ push data to a subscribing client, that data
}
```

## Setting up the transport

Because subscriptions usually maintain a persistent connection, they shouldn't use the default HTTP transport that Apollo Client uses for queries and mutations. Instead, Apollo Client subscriptions most commonly communicate over WebSocket, via the [`graphql-ws`](https://www.npmjs.com/package/graphql-ws) library.

> As mentioned in [Choosing a subscription library](#choosing-a-subscription-library), some servers use an older library called `subscriptions-transport-ws`. For necessary changes to use that library, see [below](#the-older-subscriptions-transport-ws-library).
## WebSocket setup

### 1. Install required libraries

Expand Down Expand Up @@ -186,6 +199,10 @@ const wsLink = new GraphQLWsLink(createClient({

Your `GraphQLWsLink` passes the `connectionParams` object to your server whenever it connects. Your server receives the `connectionParams` object and can use it to perform authentication, along with any other connection-related tasks.

## Subscriptions via Multipart HTTP

No additional libraries or configuration are required. Apollo Client adds the required headers to your request when the default terminating `HTTPLink` receives a subscription operation at the `uri` specified when initializing the link or Apollo Client instance.

## Executing a subscription

You use Apollo Client's `useSubscription` Hook to execute a subscription from React. Like [`useQuery`](./queries/#executing-a-query), `useSubscription` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/development-testing/static-typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export function NewRocketForm() {

### `useSubscription`

We can type our `useSubscription` hooks the same way we typed our `useQuery` and ` useMutation` hooks. Using the generated `gql` function to define our GraphQL subscriptions, we ensure that we type our subscription variables and return data:
We can type our `useSubscription` hooks the same way we typed our `useQuery` and `useMutation` hooks. Using the generated `gql` function to define our GraphQL subscriptions, we ensure that we type our subscription variables and return data:

```tsx
import React from 'react';
Expand Down
Loading

0 comments on commit 70859c3

Please sign in to comment.