I recently read an article about Apollo Client Caching on the official blog, with a screenshot here.
According to the article, if the current query contains a cached object, along with other objects, the query will be deduplicated to only query the rest of the objects.
However, I did some testing by logging out queries on the server, which suggested that the query had not been partially deduplicated. Instead, the entire query got sent to the server.
Can anyone provide any insight on this. Thanks very much.
Test:
First query:
{
post(_id: 1) {
_id
title
}
}
Second query:
{
post(_id: 1) {
_id
title
}
author(_id: 1) {
_id
firstName
}
}
Intended outcome: The secomd query received by the server only contains
author(_id: 1) {
_id
firstName
}
since post(_id: 1) has been cached after the first query is sent, according to the blog.
Actual outcome: Server log: (the second query has NOT been deduplicated)
{
"operationName": null,
"variables": {},
"query": "{\n post(_id: 1) {\n _id\n title\n __typename\n
}\n}\n"
} /graphql 200 81 - 0.520 ms
{
"operationName": null,
"variables": {},
"query": "{\n post(_id: 1) {\n _id\n title\n __typename\n
}\n author(_id: 1) {\n _id\n firstName\n __typename\n }\n}\n"
} /graphql 200 140 - 0.726 ms