Skip to content

Commit

Permalink
Add subscription support for embedded sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
William010x authored and mayakoneval committed Jul 5, 2022
1 parent e6f5da2 commit cf4868b
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 11 deletions.
98 changes: 93 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,9 @@
"size-limit": "5.0.5",
"tslib": "2.3.1",
"typescript": "3.9.10"
},
"dependencies": {
"graphql-ws": "^5.9.0",
"subscriptions-transport-ws": "^0.11.0"
}
}
36 changes: 31 additions & 5 deletions packages/explorer/src/helpers/postMessageRelayHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { GraphQLError, IntrospectionQuery } from 'graphql';
import type {
ExecutionResult,
GraphQLError,
IntrospectionQuery,
} from 'graphql';
import {
PARTIAL_AUTHENTICATION_TOKEN_RESPONSE,
EMBEDDABLE_SANDBOX_URL,
Expand All @@ -10,8 +14,9 @@ import {
EXPLORER_LISTENING_FOR_PARTIAL_TOKEN,
PARENT_LOGOUT_SUCCESS,
TRIGGER_LOGOUT_IN_PARENT,
EXPLORER_SUBSCRIPTION_RESPONSE,
} from './constants';
import type { JSONValue } from './types';
import type { JSONObject, JSONValue } from './types';

export type HandleRequest = (
endpointUrl: string,
Expand Down Expand Up @@ -46,11 +51,13 @@ export function sendPostMessageToEmbed({
embeddedIFrameElement?.contentWindow?.postMessage(message, embedUrl);
}

type Error = {
type ResponseError = {
message: string;
stack?: string;
};

export type SocketStatus = 'disconnected' | 'connecting' | 'connected';

export type OutgoingEmbedMessage =
| {
name: typeof SCHEMA_ERROR;
Expand All @@ -77,12 +84,21 @@ export type OutgoingEmbedMessage =
operationId: string;
response: {
data?: JSONValue;
error?: Error;
errors?: [Error];
error?: ResponseError;
errors?: [ResponseError];
status?: number;
headers?: Headers;
};
}
| {
name: typeof EXPLORER_SUBSCRIPTION_RESPONSE;
operationId: string;
response: {
data?: ExecutionResult<JSONObject>;
error?: Error;
errors?: [Error];
};
}
| {
name: typeof PARENT_LOGOUT_SUCCESS;
};
Expand All @@ -103,6 +119,16 @@ export type IncomingEmbedMessage = MessageEvent;
// endpointUrl?: string;
// }>
// | MessageEvent<{
// name: typeof EXPLORER_SUBSCRIPTION_REQUEST;
// operationId: string;
// operation: string;
// variables?: Record<string, string>;
// operationName?: string;
// headers?: Record<string, string>;
// subscriptionUrl: string;
// protocol: GraphQLSubscriptionLibrary;
// }>
// | MessageEvent<{
// name: typeof EXPLORER_LISTENING_FOR_SCHEMA;
// }>
// | MessageEvent<{
Expand Down
Loading

0 comments on commit cf4868b

Please sign in to comment.