-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to allow @client
fields to be sent to the link chain
#10346
Add the ability to allow @client
fields to be sent to the link chain
#10346
Conversation
🦋 Changeset detectedLatest commit: 584bd40 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
066699e
to
d640226
Compare
Very excited for what this will unlock for online/offline use cases like the one detailed in the RFC linked in #10303! I'm in favor of your design: new ApolloClient({
defaultOptions: {
transformQuery: {
clientFields: false
}
}
}); I find this intuitive especially since the "transform" in |
@alessbell you make a really good point here. One of the greatest pieces of advice I got early on in my career was to avoid negatives as its harder for the brain to think in negatives than positives. I can definitely see merit in going this route. To give some idea on why I chose this particular name, I tend to think of the option name as the thing that happens when your query goes from
On the flip side, if we like the positive connotation, I'd make 1 small tweak to your suggestion and call it
@alessbell what are your thoughts? Which naming convention do you prefer?
|
@jerelmiller that's a great point: the verb is important because all future options might not fall into the "always allow (passthrough) or never allow (remove)" case (whitespace, I see the benefits of describing the transform action itself—names like |
e4db78d
to
43b532b
Compare
…ctives-to-make-it-to-the-link-chain
…ctives-to-make-it-to-the-link-chain
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.
LGTM! 🚢
…ctives-to-make-it-to-the-link-chain
@jerelmiller heya, so I am finally back from the holidays and wanted to give this a spin today. It looks like something got lost in translation. The goal was never to have to manually go back and forth with the removeClientFields option but allow client fields to be exposed in the link, optionally. Here is where this breaks down We need to be able to work on the client fields if we have a need, but if we leave the operation with client directives in the query and/or mutation they still need to be processed as normal by the client. This seems to work for queries when |
Hey @nyteshade! Welcome back!
Yep totally understand. I'm mainly thinking about this from a "how might this be used for a broad audience" kind of way, hence the discussion about being able to toggle this transform on or off per query. Turns out that touched quite a few code paths, so I've left it as a global option.
Ah this sounds like a bug to me. That wasn't intentional, just an oversight as I had though both queries and mutations go through the same code path. Definitely something we should fix! Glad to hear queries are working as expected at least! Feel free to submit a PR if you'd like look at this, otherwise I'll try and get a fix in for this sometime in the coming week. Thanks for trying it out! |
…e link chain This undoes some of the work in #10346. With the new solution presented in this branch, I see no need for the new options.
Closes #10303
By default, Apollo core will remove fields with an
@client
directive before it makes it to the link chain. We've now got use cases that require the use of@client
in the link chain. This PR adds an option to our client to allow@client
fields to make it to the link chain. This is part of our larger effort to move local resolvers back into the link chain.Because
@client
fields now have the possibility of making it to the link chain, theHttpLink
andBatchHttpLink
links have been updated to remove@client
fields themselves. Once #10060 is done, we should be able to remove this behavior as the work to remove@client
fields will likely end up in the new Apollo link instead.Design
The API introduced in this PR is as follows:
Why is
transformQuery
an object type?I for-see the possibility of wanting more query transformation options in our client. Rather than trying to invent new names for top-level options (one of the 2 hardest things in programming), keeping them in a cohesive namespace felt like it would scale better. Imagine for example if we wanted to offer the possibility of removing whitespace from queries before they are sent to the server:
This reads nicely and keeps the name of the new option concise.
While we don't have any plans for additional transformation options at this time, I wanted something that could scale as we have/need more use cases.
Why
defaultOptions
?Thinking long-term, I could see the possibility of wanting to opt in/out of this behavior for individual queries. We allow other options (e.g.
fetchPolicy
) to have default global values which can also be overridden on a per-query basis. To keep with the spirit of this notion, I aimed to introduce this underdefaultOptions
. Because these options are applied across all query types (query
andmutation
), I opted for a new "top-level" field underdefaultOptions
to convey that these are applied to all queries.Why not allow individual queries to opt in/out of this behavior now?
While I highly considered adding this behavior, something that gave me pause is how we handle our
addTypename
feature. This option also performs query transformation, but currently this is only available as a global option. There is no way to opt in/out of this behavior for an individual query. I decided to keep things simple as this has worked well for us thus far. We can always add this functionality later.Checklist: