-
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
Inject apollo-client into operation on network layer #3877
Inject apollo-client into operation on network layer #3877
Conversation
@lucasfeliciano: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
First off, thanks very much for working on this PR @lucasfeliciano! As it stands currently, the There isn't really anything stopping us from allowing the link chain to be manipulated outside of the constructor. We're adding a We'll think about this a bit more, and post back here shortly. Thanks! |
Just to add, if we opened up the API a bit, a solution that replicates the functionality in this PR would look something like: const client = new ApolloClient({
cache: new InMemoryCache(),
});
const link = ApolloLink.from([
new ApolloLink((operation: Operation, forward: NextLink) => {
operation.client = client;
return forward(operation);
}),
// ... the rest of your link chain ...
]);
client.setLink(link); |
Closing this PR for the more flexible solution above |
Why?
I was implementing global error handling and I realise that best place to do that would be in the network layer, however it doesn't have access to
apollo-client
.The reason that I think this is super beneficial is because we can perform mutations at the network layer. Specially if you want to update a
link-state
.Motivation
After searching solutions for the my problem I ended up in this issue: apollographql/apollo-link#527
Which is exactly what I was thinking of so I decided to push this forward.
Example
First we defined a resolver in our
link-state
Then we defined our mutation:
Finally, we can perform this mutation at the network layer level:
With that we can have a component that receive the
link-state
and show the respective error in a global level.To discuss
I still have to add
client: ApolloClient
type definition intoOperation
type, but I realise that this come fromapollo-link
, so I don't know the best way of doing that.I would appreciate some help/directions on the best approach of doing that.