-
Notifications
You must be signed in to change notification settings - Fork 222
add alwaysSendQuery option for PersistedLink #1285
add alwaysSendQuery option for PersistedLink #1285
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
@alexandcote this PR could use a look if you have some time after the holidays, thanks! |
First of all, Thanks @dsanders11 for your contribution! Sorry for the delay... I will take care of reviewing this PR and assigning other folks. In the meantime, do you think you could rebase your PR on master? Thanks a lot 💯 |
@@ -46,7 +50,7 @@ export class PersistedLink extends ApolloLink { | |||
|
|||
operation.setContext({ | |||
http: { | |||
includeQuery: false, | |||
includeQuery: alwaysSendQuery, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably change this option to match the context field name (includeQuery
). The option name still bugs me a bit, because it technically applies to more than just queries, but Apollo uses "query" and "GraphQL document" interchangeably in a lot of places so it's probably fine to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever we name it, it should also be documented in the readme like idFromOperation
is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to alwaysIncludeQuery
(I think that's what you were suggesting, @lemonmade?). Originally it was "send" to align verbiage wise with the Koa middleware which has a SendAlways
option.
@gmcgibbon, documented it in the readme.
@alexandcote, rebased and addressed code review comments. |
@@ -32,7 +33,10 @@ export class PersistedLink extends ApolloLink { | |||
} | |||
|
|||
return new Observable(observer => { | |||
const {idFromOperation = defaultIdFromOperation} = this.options; | |||
const { | |||
alwaysIncludeQuery = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was proposing just includeQuery
, since this directly maps to an option with that name in Apollo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That name seems confusing to me? It loses the explicitness that the query will always be included. I'm not sure what's really gained by excluding the word always. Especially since, as I pointed out, the Koa middleware uses always to describe similar behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me, still have to determine if we keep alwaysIncludeQuery
or we switch to includeQuery
but I'm approving 💯 Thanks for your contribution
Description
Adds an option for
createPersistedLink
to always send the query, rather than waiting for the server to ask.Two motivating use-cases:
Development
This is useful for development, as it makes debugging easier when the query is visible in requests.
SSR
It's also useful when doing SSR, as upload link speed isn't a factor there, so always sending the query avoids an extra round-trip with the API server.
Usage
Type of change
Checklist