altair-graphql-core 4.4.2 → 4.5.2

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/build/config.d.ts CHANGED
@@ -13,9 +13,14 @@ export interface AltairWindowOptions {
13
13
  */
14
14
  endpointURL?: string;
15
15
  /**
16
- * URL to set as the subscription endpoint
16
+ * URL to set as the subscription endpoint. This can be relative or absolute.
17
17
  */
18
18
  subscriptionsEndpoint?: string;
19
+ /**
20
+ * URL protocol for the subscription endpoint. This is used if the specified subscriptions endpoint is relative.
21
+ * e.g. wss
22
+ */
23
+ subscriptionsProtocol?: string;
19
24
  /**
20
25
  * Initial query to be added
21
26
  */
@@ -131,6 +136,7 @@ export declare class AltairConfig {
131
136
  initialData: {
132
137
  url: string;
133
138
  subscriptionsEndpoint: string;
139
+ subscriptionsProtocol: string;
134
140
  query: string;
135
141
  variables: string;
136
142
  headers: IDictionary<any>;
@@ -145,7 +151,7 @@ export declare class AltairConfig {
145
151
  preserveState: boolean;
146
152
  windows: AltairWindowOptions[];
147
153
  };
148
- constructor({ endpointURL, subscriptionsEndpoint, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, initialSubscriptionsProvider, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, }?: AltairConfigOptions);
154
+ constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, initialSubscriptionsProvider, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, }?: AltairConfigOptions);
149
155
  }
150
156
  export declare const setAltairConfig: (_config: AltairConfig) => void;
151
157
  export declare const getAltairConfig: () => AltairConfig;
package/build/config.js CHANGED
@@ -2,7 +2,7 @@ import { WEBSOCKET_PROVIDER_ID } from './subscriptions';
2
2
  import isElectron from './utils/is_electron';
3
3
  const isTranslateMode = window.__ALTAIR_TRANSLATE__;
4
4
  export class AltairConfig {
5
- constructor({ endpointURL, subscriptionsEndpoint, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, initialSubscriptionsProvider = WEBSOCKET_PROVIDER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], } = {}) {
5
+ constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, initialSubscriptionsProvider = WEBSOCKET_PROVIDER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], } = {}) {
6
6
  this.donation = {
7
7
  url: 'https://opencollective.com/altair/donate',
8
8
  action_count_threshold: 50
@@ -38,6 +38,7 @@ export class AltairConfig {
38
38
  this.initialData = {
39
39
  url: '',
40
40
  subscriptionsEndpoint: '',
41
+ subscriptionsProtocol: '',
41
42
  query: '',
42
43
  variables: '',
43
44
  // Force type of header, since initial value inference is wrong
@@ -55,6 +56,7 @@ export class AltairConfig {
55
56
  };
56
57
  this.initialData.url = window.__ALTAIR_ENDPOINT_URL__ || endpointURL || '';
57
58
  this.initialData.subscriptionsEndpoint = window.__ALTAIR_SUBSCRIPTIONS_ENDPOINT__ || subscriptionsEndpoint || '';
59
+ this.initialData.subscriptionsProtocol = subscriptionsProtocol;
58
60
  this.initialData.query = window.__ALTAIR_INITIAL_QUERY__ || initialQuery || '';
59
61
  this.initialData.variables = window.__ALTAIR_INITIAL_VARIABLES__ || initialVariables || '';
60
62
  this.initialData.headers = window.__ALTAIR_INITIAL_HEADERS__ || initialHeaders || '';
@@ -3,11 +3,13 @@ export declare const WEBSOCKET_PROVIDER_ID = "websocket";
3
3
  export declare const GRAPHQL_WS_PROVIDER_ID = "graphql-ws";
4
4
  export declare const APP_SYNC_PROVIDER_ID = "app-sync";
5
5
  export declare const ACTION_CABLE_PROVIDER_ID = "action-cable";
6
+ export declare const GRAPHQL_SSE_ID = "graphql-sse";
6
7
  export declare const SUBSCRIPTION_PROVIDER_IDS: {
7
8
  readonly WEBSOCKET: "websocket";
8
9
  readonly GRAPHQL_WS: "graphql-ws";
9
10
  readonly APP_SYNC: "app-sync";
10
11
  readonly ACTION_CABLE: "action-cable";
12
+ readonly GRAPHQL_SSE: "graphql-sse";
11
13
  };
12
14
  export declare type SubscriptionProviderIds = typeof SUBSCRIPTION_PROVIDER_IDS[keyof typeof SUBSCRIPTION_PROVIDER_IDS];
13
15
  export interface SubscriptionProviderData {
@@ -2,9 +2,11 @@ export const WEBSOCKET_PROVIDER_ID = 'websocket';
2
2
  export const GRAPHQL_WS_PROVIDER_ID = 'graphql-ws';
3
3
  export const APP_SYNC_PROVIDER_ID = 'app-sync';
4
4
  export const ACTION_CABLE_PROVIDER_ID = 'action-cable';
5
+ export const GRAPHQL_SSE_ID = 'graphql-sse';
5
6
  export const SUBSCRIPTION_PROVIDER_IDS = {
6
7
  WEBSOCKET: WEBSOCKET_PROVIDER_ID,
7
8
  GRAPHQL_WS: GRAPHQL_WS_PROVIDER_ID,
8
9
  APP_SYNC: APP_SYNC_PROVIDER_ID,
9
- ACTION_CABLE: ACTION_CABLE_PROVIDER_ID
10
+ ACTION_CABLE: ACTION_CABLE_PROVIDER_ID,
11
+ GRAPHQL_SSE: GRAPHQL_SSE_ID,
10
12
  };
@@ -0,0 +1,11 @@
1
+ import { SubscriptionProvider, SubscriptionProviderExecuteOptions } from '../subscription-provider';
2
+ import { Observable } from 'rxjs';
3
+ import { Client } from 'graphql-sse';
4
+ export declare class GraphQLSSESubscriptionProvider extends SubscriptionProvider {
5
+ client?: Client;
6
+ cleanup?: () => void;
7
+ createClient(): void;
8
+ execute(options: SubscriptionProviderExecuteOptions): Observable<unknown>;
9
+ close(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=graphql-sse.d.ts.map
@@ -0,0 +1,39 @@
1
+ import { SubscriptionProvider } from '../subscription-provider';
2
+ import { Observable } from 'rxjs';
3
+ import { createClient } from 'graphql-sse';
4
+ export class GraphQLSSESubscriptionProvider extends SubscriptionProvider {
5
+ createClient() {
6
+ this.client = createClient({
7
+ url: this.subscriptionUrl,
8
+ headers: this.extraOptions.headers,
9
+ });
10
+ }
11
+ execute(options) {
12
+ this.createClient();
13
+ if (!this.client) {
14
+ throw new Error('Could not create subscription client!');
15
+ }
16
+ return new Observable((subscriber) => {
17
+ this.cleanup = this.client.subscribe({
18
+ query: options.query,
19
+ variables: options.variables,
20
+ operationName: options.operationName,
21
+ }, {
22
+ next: (...args) => subscriber.next(...args),
23
+ error: (...args) => subscriber.error(...args),
24
+ complete: () => subscriber.complete(),
25
+ });
26
+ });
27
+ }
28
+ async close() {
29
+ try {
30
+ this.cleanup?.();
31
+ this.cleanup = undefined;
32
+ await this.client?.dispose();
33
+ this.client = undefined;
34
+ }
35
+ catch (err) {
36
+ console.error(err);
37
+ }
38
+ }
39
+ }
@@ -6,6 +6,6 @@ export declare class GraphQLWsSubscriptionProvider extends SubscriptionProvider
6
6
  cleanup?: () => void;
7
7
  createClient(): void;
8
8
  execute(options: SubscriptionProviderExecuteOptions): Observable<unknown>;
9
- close(): void;
9
+ close(): Promise<void>;
10
10
  }
11
11
  //# sourceMappingURL=graphql-ws.d.ts.map
@@ -6,6 +6,10 @@ export class GraphQLWsSubscriptionProvider extends SubscriptionProvider {
6
6
  this.client = createClient({
7
7
  url: this.subscriptionUrl,
8
8
  connectionParams: this.connectionParams,
9
+ lazy: false,
10
+ onNonLazyError: (err) => {
11
+ this.extraOptions?.onConnected?.(err, undefined);
12
+ },
9
13
  on: {
10
14
  connected: () => {
11
15
  this.extraOptions?.onConnected?.(undefined, undefined);
@@ -33,10 +37,16 @@ export class GraphQLWsSubscriptionProvider extends SubscriptionProvider {
33
37
  });
34
38
  });
35
39
  }
36
- close() {
37
- this.cleanup?.();
38
- this.cleanup = undefined;
39
- this.client?.dispose();
40
- this.client = undefined;
40
+ async close() {
41
+ try {
42
+ this.cleanup?.();
43
+ this.cleanup = undefined;
44
+ // This causes the 'Error: Uncaught (in promise): Event: {"isTrusted":true}' error
45
+ await this.client?.dispose();
46
+ this.client = undefined;
47
+ }
48
+ catch (err) {
49
+ console.error(err);
50
+ }
41
51
  }
42
52
  }
@@ -2,6 +2,7 @@ import { Observable } from 'rxjs';
2
2
  import { IDictionary } from '../types/shared';
3
3
  export interface SubscriptionProviderExtraOptions {
4
4
  onConnected?: (error: any, data: any) => void;
5
+ headers?: IDictionary;
5
6
  }
6
7
  export interface SubscriptionProviderExecuteOptions {
7
8
  query: string;
@@ -1,3 +1,5 @@
1
+ import { PostrequestState } from './postrequest.interfaces';
2
+ import { PrerequestState } from './prerequest.interfaces';
1
3
  import { ExportWindowState } from './window.interfaces';
2
4
  export declare type SortByOptions = 'a-z' | 'z-a' | 'newest' | 'oldest';
3
5
  export interface CollectionState {
@@ -12,11 +14,13 @@ export interface IQuery extends ExportWindowState {
12
14
  updated_at?: number;
13
15
  }
14
16
  export interface IQueryCollection {
15
- id?: number;
17
+ id?: number | string;
16
18
  serverId?: number;
17
19
  title: string;
18
20
  queries: IQuery[];
19
21
  description?: string;
22
+ preRequest?: PrerequestState;
23
+ postRequest?: PostrequestState;
20
24
  /**
21
25
  * path of the collection in the collection tree
22
26
  * e.g. '/123/456'
@@ -26,7 +30,7 @@ export interface IQueryCollection {
26
30
  updated_at?: number;
27
31
  }
28
32
  export interface IQueryCollectionTree extends IQueryCollection {
29
- id: number;
33
+ id: number | string;
30
34
  collections?: IQueryCollectionTree[];
31
35
  }
32
36
  export interface ExportCollectionState extends IQueryCollectionTree {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "altair-graphql-core",
3
- "version": "4.4.2",
3
+ "version": "4.5.2",
4
4
  "description": "Several of the core logic for altair graphql client",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -53,13 +53,14 @@
53
53
  "convert-css-color-name-to-hex": "^0.1.1",
54
54
  "deepmerge": "^4.2.2",
55
55
  "graphql": "^15.5.1",
56
- "graphql-ws": "^5.1.2",
56
+ "graphql-sse": "^1.2.2",
57
+ "graphql-ws": "^5.8.2",
57
58
  "loglevel": "^1.7.1",
58
59
  "loglevel-plugin-prefix": "^0.8.4",
59
60
  "rxjs": "^7.1.0",
60
- "subscriptions-transport-ws": "^0.9.19",
61
+ "subscriptions-transport-ws": "0.9.19",
61
62
  "util": "^0.12.4",
62
63
  "uuid": "^8.3.2"
63
64
  },
64
- "gitHead": "44bf6dbb486b9afb51be1cb56228903346f515d4"
65
+ "gitHead": "9536b57d20d1e05b013adf3c0885a8bfef8e2b88"
65
66
  }