Skip to content

Commit ca6b66d

Browse files
committed
feat: We now create only single HTTP link
BREAKING CHANGE: We now create only single HTTP link. Previously we created an array of links
1 parent c27dc00 commit ca6b66d

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/index.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createHttpLink } from 'apollo-link-http';
88
import withApolloProvider from './withApolloProvider';
99

1010
let client: ApolloClient<{}>;
11+
1112
export default createPlugin({
1213
description: '🌍 A BlueBase Plugin that integrates Apollo GraphQL Client',
1314
key: 'plugin-apollo',
@@ -27,35 +28,38 @@ export default createPlugin({
2728
},
2829

2930
filters: {
30-
'bluebase.boot.end': async (bootOptions: BootOptions, _ctx: any, BB: BlueBase) => {
31-
const httpLinkOptions = BB.Configs.getValue('plugin.apollo.httpLinkOptions');
32-
const clientOptions = BB.Configs.getValue('plugin.apollo.clientOptions');
33-
34-
const httpLink = createHttpLink(httpLinkOptions);
35-
const links = await BB.Filters.run('plugin.apollo.links', [httpLink]);
36-
const cache = await BB.Filters.run('plugin.apollo.cache', new InMemoryCache());
37-
// We Use global `client` thats why we check if client create then ignore
38-
if (!client) {
39-
client = new ApolloClient({
40-
cache,
41-
link: ApolloLink.from(links),
42-
...clientOptions,
43-
});
44-
await BB.Filters.run('plugin.apollo.client', client);
45-
}
31+
'bluebase.boot.end': {
32+
key: 'apollo-register',
33+
value: async (bootOptions: BootOptions, _ctx: any, BB: BlueBase) => {
34+
if (!client) {
35+
const httpLinkOptions = BB.Configs.getValue('plugin.apollo.httpLinkOptions');
36+
const clientOptions = BB.Configs.getValue('plugin.apollo.clientOptions');
37+
38+
const httpLink = createHttpLink(httpLinkOptions);
39+
const link = await BB.Filters.run('plugin.apollo.link', httpLink);
40+
const cache = await BB.Filters.run('plugin.apollo.cache', new InMemoryCache());
4641

47-
BB.Components.addHocs('BlueBaseContent', withApolloProvider(client));
42+
client = new ApolloClient({
43+
cache,
44+
link,
45+
...clientOptions,
46+
});
47+
await BB.Filters.run('plugin.apollo.client', client);
48+
}
4849

49-
BB.Filters.register({
50-
event: 'bluebase.reset',
51-
key: 'apollo-reset',
52-
priority: 50,
53-
value: async () => {
54-
await client.clearStore();
55-
},
56-
});
50+
BB.Components.addHocs('BlueBaseContent', withApolloProvider(client));
51+
52+
BB.Filters.register({
53+
event: 'bluebase.reset',
54+
key: 'apollo-reset',
55+
priority: 50,
56+
value: async () => {
57+
await client.clearStore();
58+
},
59+
});
5760

58-
return bootOptions;
61+
return bootOptions;
62+
},
5963
},
6064
},
6165
});

0 commit comments

Comments
 (0)