destroy client
See original GitHub issueNot sure if this is a specific thing for apollo angular or just apollo client.
Anyway, when using angular apollo, we have a default client that changes depending on the user (because endpoints are different for each user.
therefor when clearing the clients I have to do that to have no errors:
private clearClient(base: ApolloBase<any> | any) {
if (base.map)
base.map.delete(USER_CLIENT);
if (base._client)
delete base._client;
const client = base.getClient();
if (client)
client.resetStore();
}
you see the check for base.map
? When the client is created it checks in the map if the client has already been created. So when reseting the store I propose it should be removed from the map. Or have a separate call like destroy()
The second check for base._client
is done to remove the _client from the object, when creating an unamed client that’s the check that is being done.
In other words this part is creating issues in apollo:
Apollo.prototype.createDefault = function (options) {
if (this.getClient()) {
throw new Error('Apollo has been already created.');
}
return this.setClient(new ApolloClient(options));
};
Apollo.prototype.createNamed = function (name, options) {
if (this.map.has(name)) {
throw new Error("Client " + name + " has been already created");
}
this.map.set(name, new ApolloBase(new ApolloClient(options)));
};
this could be added
Apollo.prototype.destroyDefault = function (options) {
return this.setClient(undefined);
};
Apollo.prototype.destroyNamed = function (name, options) {
this.map.set(name, undefined));
};
or not throw any error at all on the first snippet.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
@cedvdb @davidsandoz @danil-z Is #1151 useful? I don’t think it should include store related things in there, some folks might want to reuse a store. What do you think?
@davidsandoz
I’ve something like this