Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

add alwaysSendQuery option for PersistedLink #1285

Merged
merged 3 commits into from
Jan 16, 2021
Merged

add alwaysSendQuery option for PersistedLink #1285

merged 3 commits into from
Jan 16, 2021

Conversation

dsanders11
Copy link
Contributor

@dsanders11 dsanders11 commented Feb 15, 2020

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

createPersistedLink({
  alwaysSendQuery: process.env.NODE_ENV === 'development' || isServer
})

Type of change

  • @shopify/graphql-persisted - Minor: New feature (non-breaking change which adds functionality)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above

@ghost ghost added cla-needed and removed cla-needed labels Feb 15, 2020
@stale
Copy link

stale bot commented Oct 4, 2020

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.

@stale stale bot added stale Stale issue that hasn't received any attention in a while and removed stale Stale issue that hasn't received any attention in a while labels Oct 4, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

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.

@stale stale bot added the stale Stale issue that hasn't received any attention in a while label Dec 25, 2020
@dsanders11
Copy link
Contributor Author

@alexandcote this PR could use a look if you have some time after the holidays, thanks!

@stale stale bot removed the stale Stale issue that hasn't received any attention in a while label Dec 25, 2020
@alexandcote
Copy link
Contributor

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 💯

@alexandcote alexandcote requested a review from gmcgibbon January 4, 2021 17:35
@@ -46,7 +50,7 @@ export class PersistedLink extends ApolloLink {

operation.setContext({
http: {
includeQuery: false,
includeQuery: alwaysSendQuery,
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@dsanders11
Copy link
Contributor Author

@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,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@alexandcote alexandcote left a 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

@gmcgibbon gmcgibbon merged commit d2e31ce into Shopify:master Jan 16, 2021
@vsumner vsumner temporarily deployed to production January 20, 2021 14:24 Inactive
@sylvhama sylvhama deployed to test-react-html-fix February 5, 2021 01:49 Active
@marutypes marutypes temporarily deployed to gem February 8, 2021 15:51 Inactive
@gmcgibbon gmcgibbon temporarily deployed to production February 19, 2021 01:08 Inactive
@gmcgibbon gmcgibbon temporarily deployed to gem February 19, 2021 01:33 Inactive
@dsanders11 dsanders11 deleted the graphql-persisted-always-send-query-option branch May 28, 2021 01:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants