Skip to content

Commit

Permalink
Merge pull request #92 from apollographql/william/auto-invite-org
Browse files Browse the repository at this point in the history
NEBULA-1163: Add optional config for inviteToken and accountId
  • Loading branch information
William010x authored May 16, 2022
2 parents 7c09688 + 18b6a09 commit b930cb2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-coats-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/explorer': minor
---

Add optional config for inviteToken and accountId
8 changes: 8 additions & 0 deletions src/embeddedExplorer/EmbeddedExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export interface BaseEmbeddableExplorerOptions {

// optional. defaults to `return fetch(url, fetchOptions)`
handleRequest?: HandleRequest;
// If this object has values for `inviteToken` and `accountId`,
// any users who can see your embeddable Explorer are automatically
// invited to the account your graph is under with the role specified by the `inviteToken`.
autoInviteOptions?: {
accountId: string;
inviteToken: string;
};
}

interface EmbeddableExplorerOptionsWithSchema
Expand Down Expand Up @@ -70,6 +77,7 @@ export class EmbeddedExplorer {
updateSchemaInEmbed: this.updateSchemaInEmbed.bind(this),
schema: 'schema' in this.options ? this.options.schema : undefined,
graphRef: 'graphRef' in this.options ? this.options.graphRef : undefined,
autoInviteOptions: this.options.autoInviteOptions,
});
}

Expand Down
7 changes: 7 additions & 0 deletions src/embeddedExplorer/setupEmbedRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function setupEmbedRelay({
updateSchemaInEmbed,
schema,
graphRef,
autoInviteOptions,
}: {
endpointUrl: string;
handleRequest: HandleRequest;
Expand All @@ -34,6 +35,10 @@ export function setupEmbedRelay({
}) => void;
schema?: string | IntrospectionQuery | undefined;
graphRef?: string | undefined;
autoInviteOptions?: {
accountId: string;
inviteToken: string;
};
}) {
// Callback definition
const onPostMessageReceived = (event: IncomingEmbedMessage) => {
Expand All @@ -44,6 +49,8 @@ export function setupEmbedRelay({
message: {
name: HANDSHAKE_RESPONSE,
graphRef,
inviteToken: autoInviteOptions?.inviteToken,
accountId: autoInviteOptions?.accountId,
},
embeddedIFrameElement: embeddedExplorerIFrameElement,
embedUrl: EMBEDDABLE_EXPLORER_URL,
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/postMessageRelayHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export type OutgoingEmbedMessage =
| {
name: typeof HANDSHAKE_RESPONSE;
graphRef?: string;
inviteToken?: string;
accountId?: string;
}
| {
name: typeof PARTIAL_AUTHENTICATION_TOKEN_RESPONSE;
Expand Down

0 comments on commit b930cb2

Please sign in to comment.