@@ -8,6 +8,7 @@ import { createHttpLink } from 'apollo-link-http';
8
8
import withApolloProvider from './withApolloProvider' ;
9
9
10
10
let client : ApolloClient < { } > ;
11
+
11
12
export default createPlugin ( {
12
13
description : '🌍 A BlueBase Plugin that integrates Apollo GraphQL Client' ,
13
14
key : 'plugin-apollo' ,
@@ -27,35 +28,38 @@ export default createPlugin({
27
28
} ,
28
29
29
30
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 ( ) ) ;
46
41
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
+ }
48
49
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
+ } ) ;
57
60
58
- return bootOptions ;
61
+ return bootOptions ;
62
+ } ,
59
63
} ,
60
64
} ,
61
65
} ) ;
0 commit comments