Skip to content
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

Creating a copy() funtion for the ApolloRequest #3988

Merged

Conversation

AdamMTGreenberg
Copy link
Contributor

Purpose: to allow setting a new Operation which consumes the exact same values as an existing request and returns the result. Useful for when we want to intercept and relay the ApolloRequest through various stages of the network request.

There are various points in the API where one may want to wrap or proxy calls in the chain and without access to the Operation, we cannot. This copy function would allow the consumer to be sure that all values (beside the UUID) would be copied over, both now and in the future.

…a new Operation which consumes the exact same values as an existing request and returns the result. Useful for when we want to intercept and relay the ApolloRequest through various stages of the netowrk request.
@apollo-cla
Copy link

@AdamMTGreenberg: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@netlify
Copy link

netlify bot commented Apr 3, 2022

👷 Deploy request for apollo-android-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit fe4f41b

@AdamMTGreenberg AdamMTGreenberg changed the title Creating a copy() constructor for the ApolloRequest Creating a copy() funtion for the ApolloRequest Apr 3, 2022
return Builder(operation)
fun newBuilder(): Builder<D> = duplicate(Builder(operation))

fun copy(operation: Operation<D>): ApolloRequest<D> = duplicate(Builder(operation)).build()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this ! I understand the use case but I'd like to avoid the "copy" vocabulary here because it hints heavily at data classes which are not really used here.

Instead, maybe use newBuilder(operation: Operation<E>)? It also makes it more discoverable?

  fun newBuilder(): Builder<D> {
    return newBuilder(operation)
  }

  fun <E: Operation.Data> newBuilder(operation: Operation<E>): Builder<E> {

@martinbonnin
Copy link
Contributor

Hi 👋 . I took the liberty of pushing newBuilder(operation) as we have a new release coming up. It's @ApolloExperimental so we can always change it if needed.

Copy link
Contributor

@BoD BoD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@martinbonnin martinbonnin merged commit c8d3fb7 into apollographql:main Apr 5, 2022
BoD pushed a commit that referenced this pull request Apr 5, 2022
* Creating a copy() constructor for the ApolloRequest to allow setting a new Operation which consumes the exact same values as an existing request and returns the result. Useful for when we want to intercept and relay the ApolloRequest through various stages of the netowrk request.

* add newBuilder(operation)

Co-authored-by: Martin Bonnin <[email protected]>
(cherry picked from commit c8d3fb7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants