1
1
/* eslint-disable import/first */
2
2
3
3
import 'cross-fetch/polyfill' ;
4
- import { ApolloClient } from 'apollo- client' ;
5
- import { InMemoryCache , IntrospectionFragmentMatcher } from 'apollo-cache-inmemory ' ;
4
+ import { ApolloClient , InMemoryCache } from '@ apollo/ client' ;
5
+ import { sha256 } from 'js-sha256 ' ;
6
6
7
7
/* eslint-disable import/order */
8
8
@@ -26,17 +26,17 @@ import introspectionQueryResultData from '../temp/GraphQLFragmentTypes.json';
26
26
// const link = createHttpLink({ uri: endpoint });
27
27
28
28
// ...or a batched link (multiple queries within 10ms all go in one HTTP request)
29
- import { BatchHttpLink } from 'apollo- link- batch-http' ;
29
+ import { BatchHttpLink } from '@ apollo/client/ link/ batch-http' ;
30
30
31
31
// ...and an automatic persisted query link, which reduces bandwidth by using query hashes to alias content
32
32
// the APQ link is _chained_ behind another link that performs the actual HTTP calls, so you can choose
33
33
// APQ + batched, or APQ + http links for example.
34
- import { createPersistedQueryLink } from 'apollo- link- persisted-queries' ;
34
+ import { createPersistedQueryLink } from '@ apollo/client/ link/ persisted-queries' ;
35
35
import config from '../temp/config' ;
36
36
37
37
export default function ( endpoint , ssr , initialCacheState ) {
38
38
/* HTTP link selection: default to batched + APQ */
39
- const link = createPersistedQueryLink ( ) . concat (
39
+ const link = createPersistedQueryLink ( { sha256 } ) . concat (
40
40
new BatchHttpLink ( {
41
41
uri : endpoint ,
42
42
headers : {
@@ -46,10 +46,14 @@ export default function (endpoint, ssr, initialCacheState) {
46
46
} )
47
47
) ;
48
48
49
+ const possibleTypes = { } ;
50
+
51
+ introspectionQueryResultData . __schema . types . forEach ( ( supertype ) => {
52
+ possibleTypes [ supertype . name ] = supertype . possibleTypes . map ( ( subtype ) => subtype . name ) ;
53
+ } ) ;
54
+
49
55
const cache = new InMemoryCache ( {
50
- fragmentMatcher : new IntrospectionFragmentMatcher ( {
51
- introspectionQueryResultData,
52
- } ) ,
56
+ possibleTypes,
53
57
} ) ;
54
58
55
59
return new ApolloClient ( {
0 commit comments