@trackunit/react-core-contexts 0.4.669 → 0.4.670

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 CHANGED
@@ -5,11 +5,8 @@ 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');
9
8
  var reactCoreHooks = require('@trackunit/react-core-hooks');
10
9
  var apolloUploadClient = require('apollo-upload-client');
11
- var graphql = require('graphql');
12
- var graphqlSse = require('graphql-sse');
13
10
  var React = require('react');
14
11
  require('@js-temporal/polyfill');
15
12
  var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
@@ -88,7 +85,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
88
85
  window.location.reload();
89
86
  }
90
87
  // eslint-disable-next-line no-console
91
- console.error(`Error calling: '${errorResponse.operation.getContext().response.url}'`, errorResponse.graphQLErrors);
88
+ console.error(`Error calling: '${errorResponse.operation.getContext().clientAwareness.name}' fetching Data for: ${errorResponse.operation.operationName}`, errorResponse.graphQLErrors);
92
89
  errorResponse.graphQLErrors.forEach(error => {
93
90
  var _a, _b;
94
91
  if ("extensions" in error) {
@@ -156,42 +153,6 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
156
153
  },
157
154
  };
158
155
  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
- ]);
195
156
  return {
196
157
  client: new client.ApolloClient({
197
158
  name: "Manager",
@@ -206,7 +167,13 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
206
167
  },
207
168
  }),
208
169
  defaultOptions,
209
- link: splitLink,
170
+ link: client.from([
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
+ ]),
210
177
  }),
211
178
  setToken: (newToken) => {
212
179
  token = newToken;
package/index.esm.js CHANGED
@@ -1,13 +1,10 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { ApolloProvider, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloLink } from '@apollo/client';
2
+ import { ApolloProvider, createHttpLink, ApolloClient, InMemoryCache, from, split } 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';
7
6
  import { useEnvironment, useToken, useErrorHandler, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
8
7
  import { createUploadLink } from 'apollo-upload-client';
9
- import { print } from 'graphql';
10
- import { createClient } from 'graphql-sse';
11
8
  import * as React from 'react';
12
9
  import { useRef, useMemo, useEffect, useState } from 'react';
13
10
  import '@js-temporal/polyfill';
@@ -68,7 +65,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
68
65
  window.location.reload();
69
66
  }
70
67
  // eslint-disable-next-line no-console
71
- console.error(`Error calling: '${errorResponse.operation.getContext().response.url}'`, errorResponse.graphQLErrors);
68
+ console.error(`Error calling: '${errorResponse.operation.getContext().clientAwareness.name}' fetching Data for: ${errorResponse.operation.operationName}`, errorResponse.graphQLErrors);
72
69
  errorResponse.graphQLErrors.forEach(error => {
73
70
  var _a, _b;
74
71
  if ("extensions" in error) {
@@ -136,42 +133,6 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
136
133
  },
137
134
  };
138
135
  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
- ]);
175
136
  return {
176
137
  client: new ApolloClient({
177
138
  name: "Manager",
@@ -186,7 +147,13 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
186
147
  },
187
148
  }),
188
149
  defaultOptions,
189
- link: splitLink,
150
+ link: from([
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
+ ]),
190
157
  }),
191
158
  setToken: (newToken) => {
192
159
  token = newToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.4.669",
3
+ "version": "0.4.670",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -14,8 +14,6 @@
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",
19
17
  "@trackunit/i18n-library-translation": "*",
20
18
  "@trackunit/react-components": "*",
21
19
  "@trackunit/iris-app-api": "*",