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
* gateway: Allow use of APQ when querying downstream services.
This introduces support to Apollo Gateway which can leverage [Automated
Persisted Queries] (APQ) when communicating with downstream
implementing services in a federated architecture.
In an identical way as APQ saves bytes on the wire (read: network) in a
traditional handshake between a client and the server, this implements that behavior
in the internal communication between federated servers and the gateway that
fronts them.
This is accomplished by first attempting to utilizing a SHA-256 hex hash
(consistently, 32 bytes) of the operation which is destined for the
downstream server, rather than the complete, typically much larger query
itself.
In the event that the downstream server supports APQ (Apollo Server does by
default, unless it's been disabled), the downstream server will check its
APQ registry for the full operation body. If it has it, it will use that
cached body to process the request and return the results. If it does not
find the query in its existing registry, it will return a message to the
gateway that the query is not found in its registry, and the gateway will
re-transmit the request with the full operation payload. On receipt of this
full query, the downstream server will cache the operation for future
requests (keyed by the SHA-256 hash), and return the expected result without
further delay.
This means that once a server has warmed up its APQ registry with repeated
operations, subsequent network chatter will be greatly reduced.
Furthermore, as noted in the attached documentation, the APQ registry can be
backed by a distributed store, such as Memcached or Redis, allowing multiple
downstream GraphQL servers to share the same cache, and persist it across
restarts.
By default, APQ behavior is disabled on `RemoteGraphQLDataSource`. To
enable it, the `apq` property should be set to true. Future versions of the
`RemoteGraphQLDataSource` could negotiate this capability on their own, but
this does not attempt to make that negotiation right now.
[Automated Persisted Queries]: https://www.apollographql.com/docs/apollo-server/performance/apq/
* tests: De-compose `toHaveFetched` in preparation for similar matchers.
* tests: Introduce `toHaveFetchNth` with to test critical order of fetches.
It's plausible that we should change every existing `toHaveFetch` to use
this matcher which enforces order. Though it also seems plausible that
custom matchers aren't as flexible as they need to be in practice, since in
addition to the need to use Jest-built in methods (like the `nth`-call
matchers) there are other specific usages of this which are just surfacing
now (with APQ) that could be tested less precisely using
`expect.objectContaining()`, rather than testing concerns which are not
really necessary (like matching the hash).
If this matcher still supported partial matches then this would be possible.
However, since we're serializing the body into an `Request` before matching it
(which I'm not sure why we do and there is no comment to indicate why) this
isn't possible as Jest's matchers cannot survive that serialization.
* tests: Make `Matcher` declaration merges match new Jest definitions.
Without this change, every single usage of our `Matcher` is represented as a
type error since Jest has changed their own implementation of `Matcher` to
introduce a new generic type argument.
It's too bad that this didn't fail tests at the time that that Jest package
was updated!
* Re-jigger `RemoteGraphQLDataSource`'s `process` with new `sendRequest` method.
This introduces a new private `sendRequest` method that handles existing
behavior which existed within `RemoteGraphQLDataSource`'s `process`.
It should be a no-op change.
An upcoming commit will make multiple requests to downstream services in its
course of attempting APQ negotiation and this should facilitate that change
and avoid repetition of logic.
Apollo-Orig-Commit-AS: apollographql/apollo-server@7a8826a
Copy file name to clipboardExpand all lines: gateway-js/CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@
5
5
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.
6
6
7
7
-__BREAKING__: The behavior and signature of `RemoteGraphQLDataSource`'s `didReceiveResponse` method has been changed. No changes are necessary _unless_ your implementation has overridden the default behavior of this method by either extending the class and overriding the method or by providing `didReceiveResponse` as a parameter to the `RemoteGraphQLDataSource`'s constructor options. Implementations which have provided their own `didReceiveResponse` using either of these methods should view the PR linked here for details on what has changed. [PR #3743](https://github.com/apollographql/apollo-server/pull/3743)
8
+
-__NEW__: Setting the `apq` option to `true` on the `RemoteGraphQLDataSource` will enable the use of [automated persisted queries (APQ)](https://www.apollographql.com/docs/apollo-server/performance/apq/) when sending queries to downstream services. Depending on the complexity of queries sent to downstream services, this technique can greatly reduce the size of the payloads being transmitted over the network. Downstream implementing services must also support APQ functionality to participate in this feature (Apollo Server does by default unless it has been explicitly disabled). As with normal APQ behavior, a downstream server must have received and registered a query once before it will be able to serve an APQ request. [#3744](https://github.com/apollographql/apollo-server/pull/3744)
0 commit comments