Skip to content

Commit d14d1dc

Browse files
[React][Vue]Exception while rendering GraphQL page (#900)
* [React][Vue] Use @apollo/client and upgrade it * Add js-sha256 * Revert package
1 parent 52b445b commit d14d1dc

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

packages/create-sitecore-jss/src/templates/react/package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,17 @@
3131
},
3232
"license": "Apache-2.0",
3333
"dependencies": {
34+
"@apollo/client": "^3.5.6",
3435
"@sitecore-jss/sitecore-jss-react": "^20.0.0-canary",
35-
"apollo-cache-inmemory": "~1.6.3",
36-
"apollo-client": "~2.6.4",
37-
"apollo-link": "~1.2.13",
38-
"apollo-link-batch-http": "~1.2.13",
39-
"apollo-link-http": "~1.5.16",
40-
"apollo-link-persisted-queries": "~0.2.2",
36+
"apollo-client": "^2.6.10",
4137
"axios": "^0.21.1",
4238
"bootstrap": "^4.3.1",
4339
"cross-fetch": "^3.0.6",
4440
"deep-equal": "^2.0.5",
4541
"graphql": "~14.5.7",
4642
"graphql-tag": "~2.10.1",
4743
"i18next": "^19.9.2",
44+
"js-sha256": "^0.9.0",
4845
"react": "^17.0.2",
4946
"react-apollo": "~3.1.1",
5047
"react-app-polyfill": "^1.0.6",

packages/create-sitecore-jss/src/templates/react/src/lib/GraphQLClientFactory.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable import/first */
22

33
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';
66

77
/* eslint-disable import/order */
88

@@ -26,17 +26,17 @@ import introspectionQueryResultData from '../temp/GraphQLFragmentTypes.json';
2626
// const link = createHttpLink({ uri: endpoint });
2727

2828
// ...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';
3030

3131
// ...and an automatic persisted query link, which reduces bandwidth by using query hashes to alias content
3232
// the APQ link is _chained_ behind another link that performs the actual HTTP calls, so you can choose
3333
// 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';
3535
import config from '../temp/config';
3636

3737
export default function (endpoint, ssr, initialCacheState) {
3838
/* HTTP link selection: default to batched + APQ */
39-
const link = createPersistedQueryLink().concat(
39+
const link = createPersistedQueryLink({ sha256 }).concat(
4040
new BatchHttpLink({
4141
uri: endpoint,
4242
headers: {
@@ -46,10 +46,14 @@ export default function (endpoint, ssr, initialCacheState) {
4646
})
4747
);
4848

49+
const possibleTypes = {};
50+
51+
introspectionQueryResultData.__schema.types.forEach((supertype) => {
52+
possibleTypes[supertype.name] = supertype.possibleTypes.map((subtype) => subtype.name);
53+
});
54+
4955
const cache = new InMemoryCache({
50-
fragmentMatcher: new IntrospectionFragmentMatcher({
51-
introspectionQueryResultData,
52-
}),
56+
possibleTypes,
5357
});
5458

5559
return new ApolloClient({

packages/create-sitecore-jss/src/templates/vue/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,18 @@
4646
"lint": "vue-cli-service lint ./src/**/*.vue ./src/**/*.js ./sitecore/definitions/**/*.js ./scripts/**/*.js ./server/**/*.js ./data/**/*.yml"
4747
},
4848
"dependencies": {
49-
"@apollo/client": "~3.3.19",
49+
"@apollo/client": "^3.5.6",
5050
"@panter/vue-i18next": "~0.15.1",
5151
"@sitecore-jss/sitecore-jss-vue": "^20.0.0-canary",
5252
"@vue/apollo-composable": "^4.0.0-alpha.12",
5353
"@vue/apollo-option": "^4.0.0-alpha.11",
5454
"@vue/apollo-ssr": "^4.0.0-alpha.11",
5555
"@vue/server-renderer": "^3.0.11",
56-
"apollo-link-batch-http": "~1.2.13",
57-
"apollo-link-persisted-queries": "~0.2.2",
5856
"axios": "^0.21.1",
5957
"bootstrap": "^4.3.1",
6058
"cross-fetch": "~2.2.3",
6159
"graphql": "^15.5.0",
60+
"js-sha256": "^0.9.0",
6261
"register-service-worker": "~1.6.2",
6362
"serialize-javascript": "^5.0.1",
6463
"vue": "^v3.1.0-beta.6",

packages/create-sitecore-jss/src/templates/vue/server/server.vue.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const vueConfig = {
6060
*/
6161

6262
config.module.rules.unshift({
63-
test: /\.(?!js|vue|ts|html|graphql|gql|png|jpe?g|gif|webp|svg|woff2?|eot|ttf|otf$)[^.]+$/,
63+
test: /\.(?!js|cjs|vue|ts|html|graphql|gql|png|jpe?g|gif|webp|svg|woff2?|eot|ttf|otf$)[^.]+$/,
6464
use: {
6565
loader: 'null-loader',
6666
},

packages/create-sitecore-jss/src/templates/vue/src/lib/GraphQLClientFactory.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'cross-fetch/polyfill'; // Apollo uses `fetch`, which needs a polyfill for node and older browsers.
22
import { InMemoryCache, ApolloClient } from '@apollo/client/core';
3+
import { sha256 } from 'js-sha256';
34

45
/*
56
INTROSPECTION DATA
@@ -19,17 +20,17 @@ import introspectionQueryResultData from '../temp/GraphQLFragmentTypes.json';
1920
// choose between a basic HTTP link to run queries...
2021

2122
// ...or a batched link (multiple queries within 10ms all go in one HTTP request)
22-
import { BatchHttpLink } from 'apollo-link-batch-http';
23+
import { BatchHttpLink } from '@apollo/client/link/batch-http';
2324

2425
// ...and an automatic persisted query link, which reduces bandwidth by using query hashes to alias content
2526
// the APQ link is _chained_ behind another link that performs the actual HTTP calls, so you can choose
2627
// APQ + batched, or APQ + http links for example.
27-
import { createPersistedQueryLink } from 'apollo-link-persisted-queries';
28+
import { createPersistedQueryLink } from '@apollo/client/link/persisted-queries';
2829
import config from '../temp/config';
2930

3031
export default function (endpoint, ssr, initialCacheState) {
3132
/* HTTP link selection: default to batched + APQ */
32-
const link = createPersistedQueryLink().concat(
33+
const link = createPersistedQueryLink({ sha256 }).concat(
3334
new BatchHttpLink({
3435
uri: endpoint,
3536
headers: {

0 commit comments

Comments
 (0)