@trackunit/react-core-contexts 0.4.667 → 0.4.668
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/index.cjs.js +41 -8
- package/index.esm.js +42 -9
- package/package.json +3 -1
package/index.cjs.js
CHANGED
|
@@ -5,8 +5,11 @@ var client = require('@apollo/client');
|
|
|
5
5
|
var context = require('@apollo/client/link/context');
|
|
6
6
|
var error = require('@apollo/client/link/error');
|
|
7
7
|
var removeTypename = require('@apollo/client/link/remove-typename');
|
|
8
|
+
var utilities = require('@apollo/client/utilities');
|
|
8
9
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
9
10
|
var apolloUploadClient = require('apollo-upload-client');
|
|
11
|
+
var graphql = require('graphql');
|
|
12
|
+
var graphqlSse = require('graphql-sse');
|
|
10
13
|
var React = require('react');
|
|
11
14
|
require('@js-temporal/polyfill');
|
|
12
15
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
@@ -85,7 +88,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
85
88
|
window.location.reload();
|
|
86
89
|
}
|
|
87
90
|
// eslint-disable-next-line no-console
|
|
88
|
-
console.error(`Error calling: '${errorResponse.operation.getContext().
|
|
91
|
+
console.error(`Error calling: '${errorResponse.operation.getContext().response.url}'`, errorResponse.graphQLErrors);
|
|
89
92
|
errorResponse.graphQLErrors.forEach(error => {
|
|
90
93
|
var _a, _b;
|
|
91
94
|
if ("extensions" in error) {
|
|
@@ -153,6 +156,42 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
153
156
|
},
|
|
154
157
|
};
|
|
155
158
|
const removeTypenameLink = removeTypename.removeTypenameFromVariables();
|
|
159
|
+
class SSELink extends client.ApolloLink {
|
|
160
|
+
constructor(options) {
|
|
161
|
+
super();
|
|
162
|
+
this.client = graphqlSse.createClient(options);
|
|
163
|
+
}
|
|
164
|
+
request(operation) {
|
|
165
|
+
return new utilities.Observable(sink => {
|
|
166
|
+
return this.client.subscribe({ ...operation, query: graphql.print(operation.query) }, {
|
|
167
|
+
next: sink.next.bind(sink),
|
|
168
|
+
complete: sink.complete.bind(sink),
|
|
169
|
+
error: sink.error.bind(sink),
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const sseLink = new SSELink({
|
|
175
|
+
url: `${graphqlInternalUrl}/stream`,
|
|
176
|
+
headers: () => {
|
|
177
|
+
return {
|
|
178
|
+
Authorization: `Bearer ${token}`,
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
// Split links based on operation type
|
|
183
|
+
const splitLink = client.from([
|
|
184
|
+
authLink,
|
|
185
|
+
client.split(({ query }) => {
|
|
186
|
+
const definition = utilities.getMainDefinition(query);
|
|
187
|
+
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
|
188
|
+
}, sseLink, client.from([
|
|
189
|
+
errorLink,
|
|
190
|
+
removeTypenameLink,
|
|
191
|
+
client.split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
192
|
+
client.split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, client.split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
|
|
193
|
+
])),
|
|
194
|
+
]);
|
|
156
195
|
return {
|
|
157
196
|
client: new client.ApolloClient({
|
|
158
197
|
name: "Manager",
|
|
@@ -167,13 +206,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
167
206
|
},
|
|
168
207
|
}),
|
|
169
208
|
defaultOptions,
|
|
170
|
-
link:
|
|
171
|
-
errorLink,
|
|
172
|
-
authLink,
|
|
173
|
-
removeTypenameLink,
|
|
174
|
-
client.split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
175
|
-
client.split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, client.split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
|
|
176
|
-
]),
|
|
209
|
+
link: splitLink,
|
|
177
210
|
}),
|
|
178
211
|
setToken: (newToken) => {
|
|
179
212
|
token = newToken;
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { ApolloProvider, createHttpLink, ApolloClient, InMemoryCache,
|
|
2
|
+
import { ApolloProvider, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloLink } from '@apollo/client';
|
|
3
3
|
import { setContext } from '@apollo/client/link/context';
|
|
4
4
|
import { onError } from '@apollo/client/link/error';
|
|
5
5
|
import { removeTypenameFromVariables } from '@apollo/client/link/remove-typename';
|
|
6
|
+
import { getMainDefinition, Observable } from '@apollo/client/utilities';
|
|
6
7
|
import { useEnvironment, useToken, useErrorHandler, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
|
|
7
8
|
import { createUploadLink } from 'apollo-upload-client';
|
|
9
|
+
import { print } from 'graphql';
|
|
10
|
+
import { createClient } from 'graphql-sse';
|
|
8
11
|
import * as React from 'react';
|
|
9
12
|
import { useRef, useMemo, useEffect, useState } from 'react';
|
|
10
13
|
import '@js-temporal/polyfill';
|
|
@@ -65,7 +68,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
65
68
|
window.location.reload();
|
|
66
69
|
}
|
|
67
70
|
// eslint-disable-next-line no-console
|
|
68
|
-
console.error(`Error calling: '${errorResponse.operation.getContext().
|
|
71
|
+
console.error(`Error calling: '${errorResponse.operation.getContext().response.url}'`, errorResponse.graphQLErrors);
|
|
69
72
|
errorResponse.graphQLErrors.forEach(error => {
|
|
70
73
|
var _a, _b;
|
|
71
74
|
if ("extensions" in error) {
|
|
@@ -133,6 +136,42 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
133
136
|
},
|
|
134
137
|
};
|
|
135
138
|
const removeTypenameLink = removeTypenameFromVariables();
|
|
139
|
+
class SSELink extends ApolloLink {
|
|
140
|
+
constructor(options) {
|
|
141
|
+
super();
|
|
142
|
+
this.client = createClient(options);
|
|
143
|
+
}
|
|
144
|
+
request(operation) {
|
|
145
|
+
return new Observable(sink => {
|
|
146
|
+
return this.client.subscribe({ ...operation, query: print(operation.query) }, {
|
|
147
|
+
next: sink.next.bind(sink),
|
|
148
|
+
complete: sink.complete.bind(sink),
|
|
149
|
+
error: sink.error.bind(sink),
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const sseLink = new SSELink({
|
|
155
|
+
url: `${graphqlInternalUrl}/stream`,
|
|
156
|
+
headers: () => {
|
|
157
|
+
return {
|
|
158
|
+
Authorization: `Bearer ${token}`,
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
// Split links based on operation type
|
|
163
|
+
const splitLink = from([
|
|
164
|
+
authLink,
|
|
165
|
+
split(({ query }) => {
|
|
166
|
+
const definition = getMainDefinition(query);
|
|
167
|
+
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
|
168
|
+
}, sseLink, from([
|
|
169
|
+
errorLink,
|
|
170
|
+
removeTypenameLink,
|
|
171
|
+
split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
172
|
+
split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, split(operation => operation.getContext().clientName === "report", reportGraphQLLink, split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
|
|
173
|
+
])),
|
|
174
|
+
]);
|
|
136
175
|
return {
|
|
137
176
|
client: new ApolloClient({
|
|
138
177
|
name: "Manager",
|
|
@@ -147,13 +186,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
147
186
|
},
|
|
148
187
|
}),
|
|
149
188
|
defaultOptions,
|
|
150
|
-
link:
|
|
151
|
-
errorLink,
|
|
152
|
-
authLink,
|
|
153
|
-
removeTypenameLink,
|
|
154
|
-
split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
155
|
-
split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, split(operation => operation.getContext().clientName === "report", reportGraphQLLink, split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
|
|
156
|
-
]),
|
|
189
|
+
link: splitLink,
|
|
157
190
|
}),
|
|
158
191
|
setToken: (newToken) => {
|
|
159
192
|
token = newToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.668",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"@js-temporal/polyfill": "^0.4.4",
|
|
15
15
|
"@trackunit/iris-app-runtime-core": "*",
|
|
16
16
|
"jest-fetch-mock": "^3.0.3",
|
|
17
|
+
"graphql-sse": "^2.5.3",
|
|
18
|
+
"graphql": "^16.9.0",
|
|
17
19
|
"@trackunit/i18n-library-translation": "*",
|
|
18
20
|
"@trackunit/react-components": "*",
|
|
19
21
|
"@trackunit/iris-app-api": "*",
|