question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilkisielacommented, Apr 1, 2019

@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?

1reaction
cedvdbcommented, Mar 19, 2019

@davidsandoz

I’ve something like this

	protected clearClient(clientName?: string) {
		// the way apollo works is that for default client it's put in _client
		// the named clients are put in a map
		if (clientName)
			(this.apollo as any).map.delete(clientName);
		else
			delete (this.apollo as any)._client;

		// closing the websocket (as any) because property is private
		if (this.ws && (this.ws as any).subscriptionClient)
			(this.ws as any).subscriptionClient.close();
	}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Destroy Client - Unreal Engine 5 Documentation
Destroy Client. Windows. MacOS. Linux. Destroys the hand meshing client. Target is Magic Leap Hand Meshing Function Library. Destroy Client. Return Value.
Read more >
[clients] Calling .destroy() doesn't destroy the clients #2105
Findings: Verified by logging that destroy() is called on httpAgent and httpsAgent in NodeHttpHandler when client.destroy() is called.
Read more >
client.destroy() not working on v12 discord.js - Stack Overflow
js Found this code on this forum, it appears to work normal on the v12 client, but on mine its not working. I...
Read more >
clnt_destroy()--Destroy the RPC Client's Handle - IBM
The clnt_destroy() API destroys the RPC client's handle. This function deallocates private data structures, including the clnt parameter itself.
Read more >
Destroy Your Client Files Under a Records Retention Program
Attorneys believe that the client file belongs to the client and cannot be destroyed without the client's permission. This article focuses on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found