@jetshop/core 6.3.8-alpha.33 → 6.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChannelHandler/channelUtils.js +1 -1
- package/ChannelHandler/channelUtils.js.map +1 -1
- package/boot/apollo.js +39 -3
- package/boot/apollo.js.map +1 -1
- package/boot/client/startClient.js +16 -1
- package/boot/client/startClient.js.map +1 -1
- package/boot/server/IntervalQuery.d.ts +32 -0
- package/boot/server/IntervalQuery.js +95 -0
- package/boot/server/IntervalQuery.js.map +1 -0
- package/boot/server/IntervalQuery.test.js +276 -0
- package/boot/server/PersistedApolloClient.d.ts +20 -0
- package/boot/server/PersistedApolloClient.js +40 -0
- package/boot/server/PersistedApolloClient.js.map +1 -0
- package/boot/server/PersistedApolloClient.test.js +234 -0
- package/boot/server/createApolloServer.js +6 -0
- package/boot/server/createApolloServer.js.map +1 -1
- package/boot/server/createApolloServer.test.js +114 -0
- package/boot/server/createRenderer.d.ts +2 -2
- package/boot/server/createRenderer.js +25 -12
- package/boot/server/createRenderer.js.map +1 -1
- package/boot/server/createServer.js +11 -0
- package/boot/server/createServer.js.map +1 -1
- package/boot/server/getPreloadAssets.test.js +133 -0
- package/boot/server/index.d.ts +2 -0
- package/boot/server/index.js +16 -4
- package/boot/server/index.js.map +1 -1
- package/boot/server/persistedQueries/PersistedClient.d.ts +22 -0
- package/boot/server/persistedQueries/PersistedClient.js +58 -0
- package/boot/server/persistedQueries/PersistedClient.js.map +1 -0
- package/boot/server/persistedQueries/__tests__/getPersistedQueriesForRequest.test.js +201 -0
- package/boot/server/persistedQueries/__tests__/mockQuery.gql +6 -0
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.d.ts +3 -0
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js +27 -0
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js.map +1 -0
- package/boot/server/saleSource.test.js +39 -0
- package/boot/server/salesSource.d.ts +8 -0
- package/boot/server/salesSource.js +16 -0
- package/boot/server/salesSource.js.map +1 -0
- package/components/Auth/formFieldsFromSettings.d.ts +1 -1
- package/components/ConfigProvider.d.ts +15 -3
- package/components/ConfigProvider.js.map +1 -1
- package/components/DynamicRoute/GenericError.js +4 -0
- package/components/DynamicRoute/GenericError.js.map +1 -1
- package/components/DynamicRoute/ProductRoute.js +11 -6
- package/components/DynamicRoute/ProductRoute.js.map +1 -1
- package/components/Pagination/PaginationProvider.d.ts +2 -0
- package/components/Pagination/PaginationProvider.js +10 -1
- package/components/Pagination/PaginationProvider.js.map +1 -1
- package/components/StructuredData/StructuredProductData.d.ts +1 -1
- package/errorReporting.browser.d.ts +3 -0
- package/errorReporting.browser.js +17 -0
- package/errorReporting.browser.js.map +1 -0
- package/errorReporting.d.ts +4 -0
- package/errorReporting.js +24 -0
- package/errorReporting.js.map +1 -0
- package/errorReporting.server.d.ts +3 -0
- package/errorReporting.server.js +12 -0
- package/errorReporting.server.js.map +1 -0
- package/errorReporting.shared.d.ts +5 -0
- package/errorReporting.shared.js +17 -0
- package/errorReporting.shared.js.map +1 -0
- package/global.d.ts +1 -0
- package/hooks/usePreconnectLinks.js +5 -1
- package/hooks/usePreconnectLinks.js.map +1 -1
- package/hooks/usePreconnectLinks.test.js +4 -0
- package/package.json +6 -5
- package/polyfills.d.ts +1 -0
- package/polyfills.js +58 -0
- package/polyfills.js.map +1 -0
- package/sentry/client.d.ts +1 -0
- package/sentry/client.js +30 -0
- package/sentry/client.js.map +1 -0
- package/sentry/common.d.ts +1 -0
- package/sentry/common.js +5 -0
- package/sentry/common.js.map +1 -0
- package/sentry/server.d.ts +1 -0
- package/sentry/server.js +20 -0
- package/sentry/server.js.map +1 -0
- package/sentry/utils.d.ts +1 -0
- package/sentry/utils.js +2 -0
- package/sentry/utils.js.map +1 -0
- package/boot/worker/createApolloServerWorker.d.ts +0 -18
- package/boot/worker/createApolloServerWorker.js +0 -119
- package/boot/worker/createApolloServerWorker.js.map +0 -1
- package/boot/worker/createRenderer.d.ts +0 -23
- package/boot/worker/createRenderer.js +0 -242
- package/boot/worker/createRenderer.js.map +0 -1
- package/boot/worker/getPrefetchFiles.d.ts +0 -10
- package/boot/worker/getPrefetchFiles.js +0 -20
- package/boot/worker/getPrefetchFiles.js.map +0 -1
- package/boot/worker/getPreloadAssets.d.ts +0 -10
- package/boot/worker/getPreloadAssets.js +0 -18
- package/boot/worker/getPreloadAssets.js.map +0 -1
- package/boot/worker/index.d.ts +0 -6
- package/boot/worker/index.js +0 -98
- package/boot/worker/index.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Channel } from '@jetshop/core/types';
|
|
2
|
+
import { CreateClientOpts } from '../apollo';
|
|
3
|
+
/**
|
|
4
|
+
* Persisted Apollo Client that's shared across all requests on the server
|
|
5
|
+
*/
|
|
6
|
+
export declare class PersistedApolloClient {
|
|
7
|
+
/**
|
|
8
|
+
* **⚠️ WARNING ⚠️**
|
|
9
|
+
*
|
|
10
|
+
* Use this client with care as it's cache will be shared amongst **all** requests
|
|
11
|
+
* It's private in this class for us to be able to expose only specific queries
|
|
12
|
+
*/
|
|
13
|
+
private channelsIntervalQuery;
|
|
14
|
+
constructor({ createClientOpts, channelsPollInterval }: {
|
|
15
|
+
createClientOpts: CreateClientOpts;
|
|
16
|
+
channelsPollInterval?: number;
|
|
17
|
+
});
|
|
18
|
+
extractCache(): any;
|
|
19
|
+
getChannels(): Promise<Channel[]>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import logWarningInDev from '../../helpers/logWarningInDev';
|
|
11
|
+
import channelsQueryDefault from '../ChannelsQuery.gql';
|
|
12
|
+
import { IntervalQuery } from './IntervalQuery';
|
|
13
|
+
/**
|
|
14
|
+
* Persisted Apollo Client that's shared across all requests on the server
|
|
15
|
+
*/
|
|
16
|
+
export class PersistedApolloClient {
|
|
17
|
+
constructor({ createClientOpts, channelsPollInterval = 60e3 }) {
|
|
18
|
+
const { apolloConfig } = createClientOpts;
|
|
19
|
+
if (!apolloConfig.channelsQuery) {
|
|
20
|
+
logWarningInDev(true, `Using PersistedApolloClient without supplying the channelsQuery is deprecated and will break in the next major release.`);
|
|
21
|
+
apolloConfig.channelsQuery = channelsQueryDefault;
|
|
22
|
+
}
|
|
23
|
+
this.channelsIntervalQuery = new IntervalQuery({
|
|
24
|
+
query: apolloConfig.channelsQuery,
|
|
25
|
+
createClientOpts,
|
|
26
|
+
pollInterval: channelsPollInterval
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
extractCache() {
|
|
30
|
+
return this.channelsIntervalQuery.extractCache();
|
|
31
|
+
}
|
|
32
|
+
getChannels() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const res = yield this.channelsIntervalQuery.results();
|
|
35
|
+
const channels = res.channels;
|
|
36
|
+
return channels;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=PersistedApolloClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersistedApolloClient.js","sourceRoot":"","sources":["PersistedApolloClient.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAE5D,OAAO,oBAAoB,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAShC,YAAY,EACV,gBAAgB,EAChB,oBAAoB,GAAG,IAAI,EAI5B;QACC,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB,CAAC;QAC1C,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE;YAC/B,eAAe,CACb,IAAI,EACJ,yHAAyH,CAC1H,CAAC;YACF,YAAY,CAAC,aAAa,GAAG,oBAAoB,CAAC;SACnD;QAED,IAAI,CAAC,qBAAqB,GAAG,IAAI,aAAa,CAAC;YAC7C,KAAK,EAAE,YAAY,CAAC,aAAa;YACjC,gBAAgB;YAChB,YAAY,EAAE,oBAAoB;SACnC,CAAC,CAAC;IACL,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,qBAAqB,CAAC,YAAY,EAAE,CAAC;IACnD,CAAC;IAEY,WAAW;;YACtB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC;YAEvD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAE9B,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// TODO
|
|
2
|
+
// File reverted from TypeScript, should be reverted when pipeline supports it
|
|
3
|
+
// https://gitlab.jetshop.se/jetshop/flight/merge_requests/409/diffs?commit_id=d30490f833ec2d2eec94e5a75ed99de71e666377
|
|
4
|
+
// https://gitlab.jetshop.se/jetshop/flight/blob/94b6108017f6205e7d31f6bedb19c14f278d227a/packages/core/boot/server/PersistedApolloClient.test.ts
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ApolloClient,
|
|
8
|
+
ApolloError,
|
|
9
|
+
InMemoryCache,
|
|
10
|
+
HttpLink
|
|
11
|
+
} from '@apollo/client';
|
|
12
|
+
import { PersistedApolloClient } from './PersistedApolloClient';
|
|
13
|
+
import nock from 'nock';
|
|
14
|
+
import channelsQuery from '../ChannelsQuery.gql';
|
|
15
|
+
|
|
16
|
+
global.__IN_SERVER__ = true;
|
|
17
|
+
jest.useFakeTimers();
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
nock.disableNetConnect();
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.restoreAllMocks();
|
|
23
|
+
jest.clearAllTimers();
|
|
24
|
+
nock.enableNetConnect();
|
|
25
|
+
nock.cleanAll();
|
|
26
|
+
});
|
|
27
|
+
const apolloConfig = {
|
|
28
|
+
shopid: '...',
|
|
29
|
+
graphQLURI: 'http://localhost/graphql',
|
|
30
|
+
token: '...',
|
|
31
|
+
enableGateway: false,
|
|
32
|
+
channelsQuery
|
|
33
|
+
};
|
|
34
|
+
function getPendingResponse(persitedClient) {
|
|
35
|
+
const channelsIntervalQuery = persitedClient.channelsIntervalQuery;
|
|
36
|
+
return channelsIntervalQuery.getPendingResponse();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Mocks response for `/graphql`
|
|
40
|
+
* Only for **one** request, it resets on each call.
|
|
41
|
+
*/
|
|
42
|
+
function mockResponse({ channels = null, statusCode = 200, errors }) {
|
|
43
|
+
const data = {
|
|
44
|
+
errors,
|
|
45
|
+
data: {
|
|
46
|
+
channels: Array.isArray(channels)
|
|
47
|
+
? channels.map((channel) =>
|
|
48
|
+
Object.assign(
|
|
49
|
+
{
|
|
50
|
+
__typename: 'Channel',
|
|
51
|
+
requiresAuth: false,
|
|
52
|
+
countries: null,
|
|
53
|
+
currencies: null,
|
|
54
|
+
defaultCurrency: null,
|
|
55
|
+
defaultLanguage: null,
|
|
56
|
+
displayName: null,
|
|
57
|
+
groupName: null,
|
|
58
|
+
isDefault: null,
|
|
59
|
+
languages: null,
|
|
60
|
+
settings: null,
|
|
61
|
+
name: null,
|
|
62
|
+
url: null,
|
|
63
|
+
imageUrl: null
|
|
64
|
+
},
|
|
65
|
+
channel
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
: null
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const res = jest.fn(() => data);
|
|
72
|
+
nock('http://localhost').post('/graphql').reply(statusCode, res);
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
test('does request on init', async () => {
|
|
76
|
+
const firstCall = mockResponse({
|
|
77
|
+
channels: [
|
|
78
|
+
{
|
|
79
|
+
id: 1,
|
|
80
|
+
name: 'test'
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
const persistedClient = new PersistedApolloClient({
|
|
85
|
+
createClientOpts: { apolloConfig }
|
|
86
|
+
});
|
|
87
|
+
await getPendingResponse(persistedClient);
|
|
88
|
+
expect(firstCall).toHaveBeenCalled();
|
|
89
|
+
const channels = await persistedClient.getChannels();
|
|
90
|
+
expect(channels).toHaveLength(1);
|
|
91
|
+
expect(channels[0].id).toBe(1);
|
|
92
|
+
});
|
|
93
|
+
test('does request on intervals', async () => {
|
|
94
|
+
mockResponse({
|
|
95
|
+
channels: [
|
|
96
|
+
{
|
|
97
|
+
id: 1,
|
|
98
|
+
name: 'test1'
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
const channelsPollInterval = 60e3;
|
|
103
|
+
const persistedClient = new PersistedApolloClient({
|
|
104
|
+
createClientOpts: { apolloConfig },
|
|
105
|
+
channelsPollInterval
|
|
106
|
+
});
|
|
107
|
+
{
|
|
108
|
+
const channels = await persistedClient.getChannels();
|
|
109
|
+
expect(channels[0].name).toBe('test1');
|
|
110
|
+
}
|
|
111
|
+
{
|
|
112
|
+
mockResponse({
|
|
113
|
+
channels: [
|
|
114
|
+
{
|
|
115
|
+
id: 2,
|
|
116
|
+
name: 'test2'
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
jest.advanceTimersByTime(channelsPollInterval + 1);
|
|
121
|
+
await getPendingResponse(persistedClient);
|
|
122
|
+
const channels = await persistedClient.getChannels();
|
|
123
|
+
expect(channels[0].name).toBe('test2');
|
|
124
|
+
}
|
|
125
|
+
{
|
|
126
|
+
mockResponse({
|
|
127
|
+
channels: [
|
|
128
|
+
{
|
|
129
|
+
id: 3,
|
|
130
|
+
name: 'test3'
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
jest.advanceTimersByTime(channelsPollInterval);
|
|
135
|
+
await getPendingResponse(persistedClient);
|
|
136
|
+
const channels = await persistedClient.getChannels();
|
|
137
|
+
expect(channels[0].name).toBe('test3');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
test('propagates bad statusCodes', async () => {
|
|
141
|
+
mockResponse({ statusCode: 500 });
|
|
142
|
+
const persistedClient = new PersistedApolloClient({
|
|
143
|
+
createClientOpts: { apolloConfig }
|
|
144
|
+
});
|
|
145
|
+
expect.assertions(1);
|
|
146
|
+
try {
|
|
147
|
+
await getPendingResponse(persistedClient);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
expect(err.networkError.statusCode).toBe(500);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
test('propagates when response contains GraphQL-errors', async () => {
|
|
153
|
+
const errorMessage = 'Something went wrong';
|
|
154
|
+
mockResponse({
|
|
155
|
+
errors: [
|
|
156
|
+
{
|
|
157
|
+
message: errorMessage,
|
|
158
|
+
locations: null
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
const persistedClient = new PersistedApolloClient({
|
|
163
|
+
createClientOpts: { apolloConfig }
|
|
164
|
+
});
|
|
165
|
+
expect.assertions(2);
|
|
166
|
+
try {
|
|
167
|
+
await getPendingResponse(persistedClient);
|
|
168
|
+
} catch (_err) {
|
|
169
|
+
const err = _err;
|
|
170
|
+
expect(err).toBeInstanceOf(ApolloError);
|
|
171
|
+
expect(err.message).toBe(`GraphQL error: ${errorMessage}`);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
test('extracting and using cache in new client', async () => {
|
|
175
|
+
mockResponse({
|
|
176
|
+
channels: [
|
|
177
|
+
{
|
|
178
|
+
id: 1,
|
|
179
|
+
name: 'test1'
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
const pollInterval = 60e3;
|
|
184
|
+
const channelsPollInterval = 60e3;
|
|
185
|
+
const persistedClient = new PersistedApolloClient({
|
|
186
|
+
createClientOpts: { apolloConfig },
|
|
187
|
+
channelsPollInterval
|
|
188
|
+
});
|
|
189
|
+
await getPendingResponse(persistedClient);
|
|
190
|
+
{
|
|
191
|
+
const cache = persistedClient.extractCache();
|
|
192
|
+
expect(cache).toHaveProperty('Channel:1');
|
|
193
|
+
expect(cache['Channel:1'].name).toBe('test1');
|
|
194
|
+
const newClient = new ApolloClient({
|
|
195
|
+
link: new HttpLink(),
|
|
196
|
+
cache: new InMemoryCache().restore(cache)
|
|
197
|
+
});
|
|
198
|
+
const res = newClient.readQuery({
|
|
199
|
+
query: channelsQuery
|
|
200
|
+
});
|
|
201
|
+
expect(res.channels).toHaveLength(1);
|
|
202
|
+
expect(res.channels[0].name).toBe('test1');
|
|
203
|
+
}
|
|
204
|
+
// update data in new request
|
|
205
|
+
{
|
|
206
|
+
const mock = mockResponse({
|
|
207
|
+
channels: [
|
|
208
|
+
{
|
|
209
|
+
id: 1,
|
|
210
|
+
name: 'test1--updated'
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 2,
|
|
214
|
+
name: 'test2'
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
});
|
|
218
|
+
jest.advanceTimersByTime(pollInterval);
|
|
219
|
+
await getPendingResponse(persistedClient);
|
|
220
|
+
expect(mock).toHaveBeenCalled();
|
|
221
|
+
const cache = persistedClient.extractCache();
|
|
222
|
+
const newClient = new ApolloClient({
|
|
223
|
+
link: new HttpLink(),
|
|
224
|
+
cache: new InMemoryCache().restore(cache)
|
|
225
|
+
});
|
|
226
|
+
const res = newClient.readQuery({
|
|
227
|
+
query: channelsQuery
|
|
228
|
+
});
|
|
229
|
+
expect(res.channels).toHaveLength(2);
|
|
230
|
+
expect(res.channels[0].name).toBe('test1--updated');
|
|
231
|
+
expect(res.channels[1].name).toBe('test2');
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
//# sourceMappingURL=PersistedApolloClient.test.js.map
|
|
@@ -12,6 +12,9 @@ import { ApolloServer } from 'apollo-server-express';
|
|
|
12
12
|
import { introspectSchema, makeRemoteExecutableSchema, mergeSchemas } from 'graphql-tools';
|
|
13
13
|
import { setContext } from '@apollo/client/link/context';
|
|
14
14
|
import fetch from 'node-fetch';
|
|
15
|
+
// import { specifiedRules } from 'graphql';
|
|
16
|
+
// import { OverlappingFieldsCanBeMerged } from 'graphql/validation/rules/OverlappingFieldsCanBeMerged';
|
|
17
|
+
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
15
18
|
import https from 'https';
|
|
16
19
|
import dnscache from 'dnscache';
|
|
17
20
|
const pick = require('lodash.pick');
|
|
@@ -127,6 +130,9 @@ export default function createApolloServer({ apolloConfig, extensions = [], plug
|
|
|
127
130
|
headers
|
|
128
131
|
};
|
|
129
132
|
},
|
|
133
|
+
persistedQueries: {
|
|
134
|
+
cache: new InMemoryLRUCache()
|
|
135
|
+
},
|
|
130
136
|
tracing: false,
|
|
131
137
|
cacheControl: false,
|
|
132
138
|
engine,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApolloServer.js","sourceRoot":"","sources":["createApolloServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAY,UAAU,EAAa,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAEL,gBAAgB,EAChB,0BAA0B,EAC1B,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO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GAAyB,IAAI,CACxC,eAAe,EACf,gBAAgB,CACjB,CAAC;gBAEF,OAAO;oBACL,OAAO;iBACR,CAAC;YACJ,CAAC;YACD,gBAAgB,EAAE;gBAChB,KAAK,EAAE,IAAI,gBAAgB,EAAE;aAC9B;YACD,OAAO,EAAE,KAAK;YACd,YAAY,EAAE,KAAK;YACnB,MAAM;YACN,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAClC,CAAC;CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { ApolloServer, gql } from 'apollo-server-express';
|
|
3
|
+
import listen from './listen';
|
|
4
|
+
import createApolloServer from './createApolloServer';
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
|
+
import { GraphQLError } from 'graphql';
|
|
7
|
+
|
|
8
|
+
function createGraphqlClient(port) {
|
|
9
|
+
const url = `http://localhost:${port}/graphql`;
|
|
10
|
+
|
|
11
|
+
return async function request({ query, variables }) {
|
|
12
|
+
const body = { query, variables };
|
|
13
|
+
|
|
14
|
+
const resBody = await fetch(url, {
|
|
15
|
+
method: 'post',
|
|
16
|
+
body: JSON.stringify(body),
|
|
17
|
+
headers: { 'Content-Type': 'application/json' }
|
|
18
|
+
}).then(r => r.json());
|
|
19
|
+
|
|
20
|
+
return resBody;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function createTargetServer() {
|
|
25
|
+
const typeDefs = gql`
|
|
26
|
+
type Query {
|
|
27
|
+
hello(name: String!): String!
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const resolvers = {
|
|
32
|
+
Query: {
|
|
33
|
+
hello: async (_source, { name }) => {
|
|
34
|
+
if (name === '') {
|
|
35
|
+
throw new GraphQLError(`Name can't be empty`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return `Hello ${name}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const apolloServer = new ApolloServer({
|
|
44
|
+
typeDefs,
|
|
45
|
+
resolvers
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const app = express();
|
|
49
|
+
|
|
50
|
+
apolloServer.applyMiddleware({ app });
|
|
51
|
+
|
|
52
|
+
const { port, close } = await listen({ app, port: 0 });
|
|
53
|
+
const query = createGraphqlClient(port);
|
|
54
|
+
|
|
55
|
+
return { port, close, query };
|
|
56
|
+
}
|
|
57
|
+
async function createLocalServer({ targetPort }) {
|
|
58
|
+
const { apolloServer } = await createApolloServer({
|
|
59
|
+
apolloConfig: {
|
|
60
|
+
graphQLURI: `http://localhost:${targetPort}/graphql`
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const app = express();
|
|
65
|
+
apolloServer.applyMiddleware({ app });
|
|
66
|
+
|
|
67
|
+
const { port, close } = await listen({ app, port: 0 });
|
|
68
|
+
const query = createGraphqlClient(port);
|
|
69
|
+
|
|
70
|
+
return { port, close, query };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let targetServer;
|
|
74
|
+
let localServer;
|
|
75
|
+
|
|
76
|
+
afterEach(async () => {
|
|
77
|
+
if (localServer) {
|
|
78
|
+
await localServer.close();
|
|
79
|
+
}
|
|
80
|
+
if (targetServer) {
|
|
81
|
+
await targetServer.close();
|
|
82
|
+
}
|
|
83
|
+
localServer = null;
|
|
84
|
+
targetServer = null;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('forwarding queries', async () => {
|
|
88
|
+
targetServer = await createTargetServer();
|
|
89
|
+
localServer = await createLocalServer({ targetPort: targetServer.port });
|
|
90
|
+
|
|
91
|
+
const { data } = await localServer.query({
|
|
92
|
+
query: '{ hello(name: "World") }'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(data.hello).toBe('Hello World');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('propagating errors', async () => {
|
|
99
|
+
targetServer = await createTargetServer();
|
|
100
|
+
localServer = await createLocalServer({ targetPort: targetServer.port });
|
|
101
|
+
|
|
102
|
+
const query = '{ hello(name: "") }'; // should trigger "Name can't be empty"
|
|
103
|
+
|
|
104
|
+
const { errors: expectedErrors } = await targetServer.query({ query });
|
|
105
|
+
const { errors: actualErrors } = await localServer.query({ query });
|
|
106
|
+
|
|
107
|
+
expect(expectedErrors).toHaveLength(1);
|
|
108
|
+
expect(actualErrors).toHaveLength(1);
|
|
109
|
+
|
|
110
|
+
expect(expectedErrors[0].message).toBe(`Name can't be empty`);
|
|
111
|
+
|
|
112
|
+
expect(actualErrors[0].message).toBe(expectedErrors[0].message);
|
|
113
|
+
expect(actualErrors[0].path).toEqual(expectedErrors[0].path);
|
|
114
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ApolloClient } from '@apollo/client';
|
|
2
1
|
import { Request, Response } from 'express';
|
|
3
2
|
import { GraphQLSchema } from 'graphql';
|
|
4
3
|
import { ReactElement } from 'react';
|
|
5
4
|
import { Cookies } from 'react-cookie';
|
|
6
5
|
import { Tracker } from '../../analytics/tracking';
|
|
7
6
|
import { BootOptions, OptimizeConfig } from '../../components/ConfigProvider';
|
|
7
|
+
import { PersistedApolloClient } from './PersistedApolloClient';
|
|
8
8
|
export interface SlotData {
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
}
|
|
@@ -19,7 +19,7 @@ export interface RendererOptions extends BootOptions {
|
|
|
19
19
|
singleDomainMode: boolean;
|
|
20
20
|
trackers?: Tracker[];
|
|
21
21
|
optimize?: OptimizeConfig;
|
|
22
|
-
globalClient?:
|
|
22
|
+
globalClient?: PersistedApolloClient;
|
|
23
23
|
}
|
|
24
24
|
declare const createRenderer: (template: string, tree: ReactElement<any>, options: RendererOptions) => (req: Request & {
|
|
25
25
|
universalCookies: Cookies;
|
|
@@ -15,6 +15,7 @@ import React from 'react';
|
|
|
15
15
|
import { renderToString } from 'react-dom/server';
|
|
16
16
|
import { ChunkExtractor, ChunkExtractorManager } from '@loadable/server';
|
|
17
17
|
import { StaticRouter } from 'react-router-dom';
|
|
18
|
+
import { createPolyfill } from '../../polyfills';
|
|
18
19
|
import { getActiveFiltersFromSearch } from '../../resolvers/filters/filterParams';
|
|
19
20
|
import { createClient } from '../apollo';
|
|
20
21
|
import SharedTree from '../SharedTree';
|
|
@@ -24,6 +25,9 @@ import { ChannelHandler } from '../../ChannelHandler/ChannelHandler';
|
|
|
24
25
|
import { AuthHandler } from '../AuthHandler';
|
|
25
26
|
import { PreviewHandler } from '../PreviewHandler';
|
|
26
27
|
import isBot from 'isbot';
|
|
28
|
+
import { getPersistedQueriesForRequest } from './persistedQueries/getPersistedQueriesForRequest';
|
|
29
|
+
import _merge from 'lodash.merge';
|
|
30
|
+
import { salesSourceMiddleware } from './salesSource';
|
|
27
31
|
import { getPreloadLinkHeaderString } from './getPreloadAssets';
|
|
28
32
|
import { primaryRouteForPathFetcher } from '../../../core/ChannelHandler/redirectUtils';
|
|
29
33
|
import ActiveFiltersQuery from '@jetshop/core/components/DynamicRoute/ActiveFiltersQuery.gql';
|
|
@@ -31,7 +35,7 @@ import AuthProvider from '@jetshop/core/components/AuthContext/AuthProvider';
|
|
|
31
35
|
const injectDataIntoSlots = (template, data) => Object.keys(data).reduce((output, key) => key !== 'htmlAttributes'
|
|
32
36
|
? output.replace(`<slot name="${key}"/>`, data[key])
|
|
33
37
|
: output.replace('<html lang="en">', `<html ${data[key]}>`), template);
|
|
34
|
-
const wrapTree = (tree, req, renderOptions, client, channelHandler, authHandler, previewHandler, translator, config, extractor) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const wrapTree = (tree, req, renderOptions, client, channelHandler, authHandler, previewHandler, translator, locale, config, extractor) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
39
|
var _a;
|
|
36
40
|
const modules = [];
|
|
37
41
|
const routerContext = { url: null, statusCode: 200 };
|
|
@@ -52,7 +56,7 @@ const wrapTree = (tree, req, renderOptions, client, channelHandler, authHandler,
|
|
|
52
56
|
yield getDataFromTree(wrappedTree);
|
|
53
57
|
}
|
|
54
58
|
catch (e) {
|
|
55
|
-
//
|
|
59
|
+
// Don't log to Sentry here as we're already logging query errors in a
|
|
56
60
|
// middleware and JS errors further down in `handleError` and then
|
|
57
61
|
// again on the client if it fails to recover
|
|
58
62
|
if (e.message ===
|
|
@@ -87,7 +91,8 @@ const wrapTree = (tree, req, renderOptions, client, channelHandler, authHandler,
|
|
|
87
91
|
routerUrl: routerContext.url,
|
|
88
92
|
statusCode: routerContext.statusCode,
|
|
89
93
|
helmet: helmetContext.helmet,
|
|
90
|
-
apolloState
|
|
94
|
+
apolloState,
|
|
95
|
+
polyfill: createPolyfill(locale, config.usePolyfilling)
|
|
91
96
|
};
|
|
92
97
|
});
|
|
93
98
|
const startResponse = ({ res, head, statusCode }) => {
|
|
@@ -99,22 +104,25 @@ const endResponse = ({ res, foot }) => {
|
|
|
99
104
|
res.write(foot);
|
|
100
105
|
res.end();
|
|
101
106
|
};
|
|
107
|
+
const persistedQueryClients = {};
|
|
102
108
|
const createRenderer = (template, tree, options) => {
|
|
103
109
|
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
-
|
|
110
|
+
var _a;
|
|
111
|
+
const { apolloConfig, loadableStatsPath, intl, schema, globalClient, disableGeoRedirect, singleDomainMode, usePolyfilling = false } = options;
|
|
105
112
|
// Set response headers immediately
|
|
106
113
|
res.setHeader('Content-Type', 'text/html');
|
|
107
114
|
const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
|
|
108
115
|
const cookies = req.universalCookies;
|
|
116
|
+
salesSourceMiddleware({
|
|
117
|
+
queryObject: req.query,
|
|
118
|
+
cookies
|
|
119
|
+
});
|
|
109
120
|
// geoIP is set in the load balancer
|
|
110
121
|
const geoipCountry = req.header('x-geoip-country');
|
|
111
122
|
const acceptedLanguages = req.headers['accept-language']
|
|
112
123
|
? req.headers['accept-language']
|
|
113
124
|
: '';
|
|
114
|
-
const
|
|
115
|
-
query: apolloConfig.channelsQuery
|
|
116
|
-
});
|
|
117
|
-
const channels = response.data.channels;
|
|
125
|
+
const channels = yield globalClient.getChannels();
|
|
118
126
|
const { selectedChannel, recommendedChannel, redirect, group } = getSelectedAndRecommendedChannel({
|
|
119
127
|
url: fullUrl,
|
|
120
128
|
singleDomainMode,
|
|
@@ -153,8 +161,11 @@ const createRenderer = (template, tree, options) => {
|
|
|
153
161
|
});
|
|
154
162
|
return res.redirect(302, redirectUrl);
|
|
155
163
|
}
|
|
156
|
-
const
|
|
157
|
-
|
|
164
|
+
const persistedQueries = yield ((_a = getPersistedQueriesForRequest(persistedQueryClients, createClientOpts)) === null || _a === void 0 ? void 0 : _a.extractCache());
|
|
165
|
+
// Merge channel and persisted query caches
|
|
166
|
+
const cachedChannels = yield globalClient.extractCache();
|
|
167
|
+
const combinedCache = _merge({}, cachedChannels, persistedQueries);
|
|
168
|
+
client.cache.restore(combinedCache);
|
|
158
169
|
// Initialise cache with active filters from the search params
|
|
159
170
|
client.cache.writeQuery({
|
|
160
171
|
query: ActiveFiltersQuery,
|
|
@@ -166,7 +177,7 @@ const createRenderer = (template, tree, options) => {
|
|
|
166
177
|
selectedChannel,
|
|
167
178
|
options: intl.options
|
|
168
179
|
});
|
|
169
|
-
const { translator } = yield setupIntl({
|
|
180
|
+
const { translator, locale } = yield setupIntl({
|
|
170
181
|
translations: intl.translations,
|
|
171
182
|
locale: selectedChannel.language.culture,
|
|
172
183
|
defaultLocale: intl.defaultLocale,
|
|
@@ -186,9 +197,10 @@ const createRenderer = (template, tree, options) => {
|
|
|
186
197
|
statsFile: loadableStatsPath,
|
|
187
198
|
entrypoints: ['client']
|
|
188
199
|
});
|
|
189
|
-
const { wrappedTree, routerUrl, statusCode, helmet: { htmlAttributes, title, meta, style, link }, apolloState } = yield wrapTree(tree, req, options, client, channelHandler, authHandler, previewHandler, translator, {
|
|
200
|
+
const { wrappedTree, routerUrl, statusCode, helmet: { htmlAttributes, title, meta, style, link }, apolloState, polyfill } = yield wrapTree(tree, req, options, client, channelHandler, authHandler, previewHandler, translator, locale, {
|
|
190
201
|
loginPath: options.loginPath,
|
|
191
202
|
pathsWithNoAuthRequired: options.pathsWithNoAuthRequired,
|
|
203
|
+
usePolyfilling
|
|
192
204
|
}, chunkExtractor);
|
|
193
205
|
if (routerUrl) {
|
|
194
206
|
return res.redirect(
|
|
@@ -212,6 +224,7 @@ const createRenderer = (template, tree, options) => {
|
|
|
212
224
|
const statusCodeScript = `<script>window.__STATUS_CODE__ = '${statusCode}';</script>`;
|
|
213
225
|
const data = {
|
|
214
226
|
apolloState: apolloState,
|
|
227
|
+
polyfill,
|
|
215
228
|
preloadLinks,
|
|
216
229
|
preloadScripts: geoipCountryScript +
|
|
217
230
|
acceptedLanguagesScript +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.js","sourceRoot":"","sources":["createRenderer.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAIhD,OAAO,KAAuB,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"create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,GAAG,aAAa;YAC1D,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE;SAC1C,CAAC;QAEF,MAAM,IAAI,GAAG,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACjD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAEvD,aAAa,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACzC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC;QACvC,WAAW,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
1
2
|
import express from 'express';
|
|
2
3
|
import compression from 'compression';
|
|
3
4
|
import breakpointMiddleware from '@jetshop/core/boot/server/breakpointMiddleware';
|
|
4
5
|
import cookiesMiddleware from 'universal-cookie-express';
|
|
6
|
+
import report from '../../errorReporting';
|
|
5
7
|
// Makes the script crash on unhandled rejections instead of silently
|
|
6
8
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
7
9
|
// terminate the Node.js process with a non-zero exit code.
|
|
8
10
|
process.on('unhandledRejection', (err) => {
|
|
11
|
+
report(err, { reason: 'unhandledRejection' });
|
|
9
12
|
throw err;
|
|
10
13
|
});
|
|
11
14
|
const createServer = ({ apolloServer, middlewares }) => {
|
|
12
15
|
const app = express();
|
|
16
|
+
// The Sentry.io request handler must be the first middleware on the app
|
|
17
|
+
if (__USE_SENTRY__) {
|
|
18
|
+
app.use(Sentry.Handlers.requestHandler());
|
|
19
|
+
}
|
|
13
20
|
app.set('trust proxy', true);
|
|
14
21
|
app.use(compression());
|
|
15
22
|
app.use(breakpointMiddleware);
|
|
@@ -25,6 +32,10 @@ const createServer = ({ apolloServer, middlewares }) => {
|
|
|
25
32
|
app.use(express.static(process.env.RAZZLE_PUBLIC_DIR, {
|
|
26
33
|
maxAge: '365d'
|
|
27
34
|
}));
|
|
35
|
+
// The error handler must be before any other error middleware
|
|
36
|
+
if (__USE_SENTRY__) {
|
|
37
|
+
app.use(Sentry.Handlers.errorHandler());
|
|
38
|
+
}
|
|
28
39
|
return app;
|
|
29
40
|
};
|
|
30
41
|
export default createServer;
|